From 6435e703e4be2515d811f52f3380e9eb778c2ff2 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 25 Feb 2024 15:09:02 +0100 Subject: [PATCH] feat: Add insert content via gboard --- lib/pages/chat/input_bar.dart | 28 +++++++++++---- .../homeserver_picker/homeserver_app_bar.dart | 25 +++++++------ pubspec.lock | 36 +++++++++++++++---- pubspec.yaml | 2 +- 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 7f1936de1..ff5f58bfc 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -444,13 +444,29 @@ class InputBar extends StatelessWidget { ), }, child: TypeAheadField>( - 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 suggestion) => + onSelected: (Map 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 ), ), diff --git a/lib/pages/homeserver_picker/homeserver_app_bar.dart b/lib/pages/homeserver_picker/homeserver_app_bar.dart index f7f693515..9ae168f97 100644 --- a/lib/pages/homeserver_picker/homeserver_app_bar.dart +++ b/lib/pages/homeserver_picker/homeserver_app_bar.dart @@ -18,13 +18,17 @@ class HomeserverAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return TypeAheadField( - suggestionsBoxDecoration: SuggestionsBoxDecoration( - borderRadius: BorderRadius.circular(AppConfig.borderRadius), - elevation: Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4, - shadowColor: Theme.of(context).appBarTheme.shadowColor ?? Colors.black, + decorationBuilder: (context, child) => ConstrainedBox( constraints: const BoxConstraints(maxHeight: 256), + child: Material( + borderRadius: BorderRadius.circular(AppConfig.borderRadius), + elevation: Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4, + shadowColor: + Theme.of(context).appBarTheme.shadowColor ?? Colors.black, + child: child, + ), ), - noItemsFoundBuilder: (context) => ListTile( + emptyBuilder: (context) => ListTile( leading: const Icon(Icons.search_outlined), title: Text(L10n.of(context)!.nothingFound), ), @@ -35,8 +39,7 @@ class HomeserverAppBar extends StatelessWidget { errorBuilder: (context, error) => ListTile( leading: const Icon(Icons.error_outlined), title: Text( - error?.toLocalizedString(context) ?? - L10n.of(context)!.oopsSomethingWentWrong, + error.toLocalizedString(context), ), ), itemBuilder: (context, homeserver) => ListTile( @@ -72,13 +75,15 @@ class HomeserverAppBar extends StatelessWidget { } return matches; }, - onSuggestionSelected: (suggestion) { + onSelected: (suggestion) { controller.homeserverController.text = suggestion.name; controller.checkHomeserverAction(); }, - textFieldConfiguration: TextFieldConfiguration( + controller: controller.homeserverController, + builder: (context, textEditingController, focusNode) => TextField( enabled: !controller.isLoggingIn, - controller: controller.homeserverController, + controller: textEditingController, + focusNode: focusNode, decoration: InputDecoration( prefixIcon: Navigator.of(context).canPop() ? IconButton( diff --git a/pubspec.lock b/pubspec.lock index 29dc21ffe..4c79293db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -471,10 +471,10 @@ packages: dependency: transitive description: name: flutter_keyboard_visibility - sha256: "4983655c26ab5b959252ee204c2fffa4afeb4413cd030455194ec0caa3b8e7cb" + sha256: "98664be7be0e3ffca00de50f7f6a287ab62c763fc8c762e0a21584584a3ff4f8" url: "https://pub.dev" source: hosted - version: "5.4.1" + version: "6.0.0" flutter_keyboard_visibility_linux: dependency: transitive description: @@ -698,10 +698,10 @@ packages: dependency: "direct main" description: name: flutter_typeahead - sha256: b9942bd5b7611a6ec3f0730c477146cffa4cd4b051077983ba67ddfc9e7ee818 + sha256: d64712c65db240b1057559b952398ebb6e498077baeebf9b0731dade62438a6d url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "5.2.0" flutter_web_auth_2: dependency: "direct main" description: @@ -1394,10 +1394,34 @@ packages: dependency: transitive description: name: pointer_interceptor - sha256: adf7a637f97c077041d36801b43be08559fd4322d2127b3f20bb7be1b9eebc22 + sha256: bd18321519718678d5fa98ad3a3359cbc7a31f018554eab80b73d08a7f0c165a + url: "https://pub.dev" + source: hosted + version: "0.10.1" + pointer_interceptor_ios: + dependency: transitive + description: + name: pointer_interceptor_ios + sha256: "2e73c39452830adc4695757130676a39412a3b7f3c34e3f752791b5384770877" + url: "https://pub.dev" + source: hosted + version: "0.10.0+2" + pointer_interceptor_platform_interface: + dependency: transitive + description: + name: pointer_interceptor_platform_interface + sha256: "0597b0560e14354baeb23f8375cd612e8bd4841bf8306ecb71fcd0bb78552506" + url: "https://pub.dev" + source: hosted + version: "0.10.0+1" + pointer_interceptor_web: + dependency: transitive + description: + name: pointer_interceptor_web + sha256: "9386e064097fd16419e935c23f08f35b58e6aaec155dd39bd6a003b88f9c14b4" url: "https://pub.dev" source: hosted - version: "0.9.3+7" + version: "0.10.1+2" pointycastle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 659e79176..40db892a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,7 +49,7 @@ dependencies: flutter_secure_storage: ^9.0.0 flutter_shortcuts: git: https://github.com/krille-chan/flutter_shortcuts.git - flutter_typeahead: ^4.8.0 + flutter_typeahead: ^5.2.0 flutter_web_auth_2: ^3.0.4 flutter_webrtc: ^0.9.46 future_loading_dialog: ^0.3.0