From a59a6730c9ac108db7aeaee19275a2cff80fe629 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:52:36 -0500 Subject: [PATCH] uncomment typeaheadfield (#1141) --- lib/pages/chat/input_bar.dart | 175 +++++++++++++++++----------------- 1 file changed, 86 insertions(+), 89 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index fcd428c8d..a4677e47e 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -4,10 +4,12 @@ import 'package:fluffychat/pages/chat/command_hints.dart'; import 'package:fluffychat/pangea/widgets/igc/pangea_text_controller.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/avatar.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:matrix/matrix.dart'; import 'package:pasteboard/pasteboard.dart'; import 'package:slugify/slugify.dart'; @@ -457,102 +459,97 @@ class InputBar extends StatelessWidget { }, ), }, - // #Pangea - // child: TypeAheadField>( - // direction: VerticalDirection.up, - // hideOnEmpty: true, - // hideOnLoading: true, - // controller: controller, - // focusNode: focusNode, - // hideOnSelect: false, - // debounceDuration: const Duration(milliseconds: 50), - // // show suggestions after 50ms idle time (default is 300) - // // #Pangea - // // key: controller?.choreographer.inputLayerLinkAndKey.key, - // // builder: (context, controller, focusNode) => TextField( - // builder: (context, _, focusNode) => - child: TextField( - enableSuggestions: false, - readOnly: controller != null && controller!.choreographer.isRunningIT, - autocorrect: false, - // Pangea# + child: TypeAheadField>( + direction: VerticalDirection.up, + hideOnEmpty: true, + hideOnLoading: true, controller: controller, focusNode: focusNode, - contentInsertionConfiguration: ContentInsertionConfiguration( - onContentInserted: (KeyboardInsertedContent content) { - final data = content.data; - if (data == null) return; + hideOnSelect: false, + debounceDuration: const Duration(milliseconds: 50), + // show suggestions after 50ms idle time (default is 300) + // #Pangea + // builder: (context, controller, focusNode) => TextField( + builder: (context, _, focusNode) => TextField( + enableSuggestions: false, + readOnly: + controller != null && controller!.choreographer.isRunningIT, + autocorrect: false, + // Pangea# + 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.uri.split('/').last, - ); - room.sendFileEvent( - file, - shrinkImageMaxDimension: 1600, + final file = MatrixFile( + mimeType: content.mimeType, + bytes: data, + name: content.uri.split('/').last, + ); + room.sendFileEvent( + file, + shrinkImageMaxDimension: 1600, + ); + }, + ), + minLines: minLines, + maxLines: maxLines, + keyboardType: keyboardType!, + textInputAction: textInputAction, + autofocus: autofocus!, + inputFormatters: [ + //#Pangea + //LengthLimitingTextInputFormatter((maxPDUSize / 3).floor()), + //setting max character count to 1000 + //after max, nothing else can be typed + LengthLimitingTextInputFormatter(1000), + //Pangea# + ], + onSubmitted: (text) { + // fix for library for now + // it sets the types for the callback incorrectly + onSubmitted!(text); + }, + // #Pangea + style: controller?.exceededMaxLength ?? false + ? const TextStyle(color: Colors.red) + : null, + onTap: () { + controller?.onInputTap( + context, + fNode: focusNode, ); }, + // Pangea# + decoration: decoration!, + onChanged: (text) { + // fix for the library for now + // it sets the types for the callback incorrectly + onChanged!(text); + }, + textCapitalization: TextCapitalization.sentences, ), - minLines: minLines, - maxLines: maxLines, - keyboardType: keyboardType!, - textInputAction: textInputAction, - autofocus: autofocus!, - inputFormatters: [ - //#Pangea - //LengthLimitingTextInputFormatter((maxPDUSize / 3).floor()), - //setting max character count to 1000 - //after max, nothing else can be typed - LengthLimitingTextInputFormatter(1000), - //Pangea# - ], - onSubmitted: (text) { - // fix for library for now - // it sets the types for the callback incorrectly - onSubmitted!(text); - }, - // #Pangea - style: controller?.exceededMaxLength ?? false - ? const TextStyle(color: Colors.red) - : null, - onTap: () { - controller?.onInputTap( - context, - fNode: focusNode, - ); - }, - // Pangea# - decoration: decoration!, - onChanged: (text) { - // fix for the library for now - // it sets the types for the callback incorrectly - onChanged!(text); - }, - textCapitalization: TextCapitalization.sentences, + suggestionsCallback: getSuggestions, + itemBuilder: (c, s) => + buildSuggestion(c, s, Matrix.of(context).client), + 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 + emptyBuilder: (BuildContext context) => const SizedBox + .shrink(), // fix loading briefly showing no suggestions + // If we ever want to change the suggestion background color + // here is the code for it + // decorationBuilder: (context, child) => Material( + // borderRadius: BorderRadius.circular(AppConfig.borderRadius), + // color: Theme.of(context).colorScheme.surfaceContainerHigh, + // child: child, + // ), ), - // #Pangea - // suggestionsCallback: getSuggestions, - // itemBuilder: (c, s) => - // buildSuggestion(c, s, Matrix.of(context).client), - // 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 - // emptyBuilder: (BuildContext context) => const SizedBox - // .shrink(), // fix loading briefly showing no suggestions - - // If we ever want to change the suggestion background color - // here is the code for it - // decorationBuilder: (context, child) => Material( - // borderRadius: BorderRadius.circular(AppConfig.borderRadius), - // color: Theme.of(context).colorScheme.surfaceContainerHigh, - // child: child, - // ), - - // ), // Pangea# ), );