feat: Add insert content via gboard

This commit is contained in:
krille-chan 2024-02-25 15:09:02 +01:00
commit 6435e703e4
No known key found for this signature in database
4 changed files with 67 additions and 24 deletions

View file

@ -444,13 +444,29 @@ class InputBar extends StatelessWidget {
),
},
child: TypeAheadField<Map<String, String?>>(
direction: AxisDirection.up,
direction: VerticalDirection.up,
hideOnEmpty: true,
hideOnLoading: true,
keepSuggestionsOnSuggestionSelected: true,
controller: controller,
focusNode: focusNode,
hideOnSelect: false,
debounceDuration: const Duration(milliseconds: 50),
// show suggestions after 50ms idle time (default is 300)
textFieldConfiguration: TextFieldConfiguration(
builder: (context, controller, focusNode) => TextField(
controller: controller,
focusNode: focusNode,
contentInsertionConfiguration: ContentInsertionConfiguration(
onContentInserted: (KeyboardInsertedContent content) {
final data = content.data;
if (data == null) return;
final file = MatrixFile(
mimeType: content.mimeType,
bytes: data,
name: 'content-insertion',
);
room.sendFileEvent(file, shrinkImageMaxDimension: 1600);
},
),
minLines: minLines,
maxLines: maxLines,
keyboardType: keyboardType!,
@ -461,9 +477,7 @@ class InputBar extends StatelessWidget {
// it sets the types for the callback incorrectly
onSubmitted!(text);
},
controller: controller,
decoration: decoration!,
focusNode: focusNode,
onChanged: (text) {
// fix for the library for now
// it sets the types for the callback incorrectly
@ -474,13 +488,13 @@ class InputBar extends StatelessWidget {
suggestionsCallback: getSuggestions,
itemBuilder: (c, s) =>
buildSuggestion(c, s, Matrix.of(context).client),
onSuggestionSelected: (Map<String, String?> suggestion) =>
onSelected: (Map<String, String?> suggestion) =>
insertSuggestion(context, suggestion),
errorBuilder: (BuildContext context, Object? error) =>
const SizedBox.shrink(),
loadingBuilder: (BuildContext context) => const SizedBox.shrink(),
// fix loading briefly flickering a dark box
noItemsFoundBuilder: (BuildContext context) => const SizedBox
emptyBuilder: (BuildContext context) => const SizedBox
.shrink(), // fix loading briefly showing no suggestions
),
),