From c68b0d60cc6d6b39bd6f2562edc26fc7cdb30d88 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Fri, 21 Aug 2020 15:18:02 +0500 Subject: [PATCH 1/8] add prefilled text add text to the FlutterMentions widget --- lib/src/mention_view.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index 8d339b7..d301fab 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -4,6 +4,7 @@ class FlutterMentions extends StatefulWidget { FlutterMentions({ @required this.mentions, Key key, + this.text, this.suggestionPosition = SuggestionPosition.Bottom, this.suggestionListHeight = 300.0, this.onMarkupChanged, @@ -46,6 +47,9 @@ class FlutterMentions extends StatefulWidget { this.appendSpaceOnAdd = true, }) : super(key: key); + /// text + final text; + /// List of Mention that the user is allowed to triggered final List mentions; @@ -265,6 +269,8 @@ class FlutterMentionsState extends State { controller = AnnotationEditingController(data); + controller.text = widget.text; + // setup a listener to figure out which suggestions to show based on the trigger controller.addListener(() { final cursorPos = controller.selection.baseOffset; From 981db3f255a1b6985000dc20d9e046faa8f96da0 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Fri, 21 Aug 2020 15:25:31 +0500 Subject: [PATCH 2/8] add type to text --- lib/src/mention_view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index d301fab..bf34397 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -48,7 +48,7 @@ class FlutterMentions extends StatefulWidget { }) : super(key: key); /// text - final text; + final String text; /// List of Mention that the user is allowed to triggered final List mentions; From 1be836dc8fde6a122f6fb2cd1e37bc28338a8204 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Sat, 22 Aug 2020 12:19:24 +0500 Subject: [PATCH 3/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f45bc5d..d7ecfb9 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,10 @@ To use this package you must first wrap your top most widget with `Portal` as th - `suggestionListHeight: double` - Max height for the suggestion list. Defaults for 300.0. - `onMarkupChanged: Function(String)` - A Functioned which is triggered when ever the input changes but with the markup of the selected mentions. - `suggestionListDecoration: BoxDecoration` - Decoration for the Suggestion list. +- `text: String` - Populate your input field with pre-filled text. - Supports all the other properties that `TextField` supports. + **Mention** - `trigger: String` - A single character that will be used to trigger the suggestions. From 7722d6af64eab4e62dc04c2745f107671bd73368 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Sat, 22 Aug 2020 12:25:06 +0500 Subject: [PATCH 4/8] change text variable to defaultText --- README.md | 2 +- lib/src/mention_view.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d7ecfb9..4fb8b7d 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ To use this package you must first wrap your top most widget with `Portal` as th - `suggestionListHeight: double` - Max height for the suggestion list. Defaults for 300.0. - `onMarkupChanged: Function(String)` - A Functioned which is triggered when ever the input changes but with the markup of the selected mentions. - `suggestionListDecoration: BoxDecoration` - Decoration for the Suggestion list. -- `text: String` - Populate your input field with pre-filled text. +- `defaultText: String` - Populate your input field with pre-filled text. - Supports all the other properties that `TextField` supports. diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index bf34397..d75fd60 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -4,7 +4,7 @@ class FlutterMentions extends StatefulWidget { FlutterMentions({ @required this.mentions, Key key, - this.text, + this.defaultText, this.suggestionPosition = SuggestionPosition.Bottom, this.suggestionListHeight = 300.0, this.onMarkupChanged, @@ -48,7 +48,7 @@ class FlutterMentions extends StatefulWidget { }) : super(key: key); /// text - final String text; + final String defaultText; /// List of Mention that the user is allowed to triggered final List mentions; @@ -269,7 +269,7 @@ class FlutterMentionsState extends State { controller = AnnotationEditingController(data); - controller.text = widget.text; + controller.text = widget.defaultText; // setup a listener to figure out which suggestions to show based on the trigger controller.addListener(() { From 2b2393458b75876c75d5b87f468e4c78f8439513 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Mon, 24 Aug 2020 12:16:40 +0500 Subject: [PATCH 5/8] hide suggestions on unfocus There was an issue when of not hiding suggestions. Steps: add @menstion someone and then remove it with 'backspace' and hide the keyboard --- .vscode/launch.json | 14 ++++++++++++++ lib/src/mention_view.dart | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0c89af4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter", + "program": "example/lib/main.dart", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index d75fd60..a57ea56 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -270,7 +270,7 @@ class FlutterMentionsState extends State { controller = AnnotationEditingController(data); controller.text = widget.defaultText; - + // setup a listener to figure out which suggestions to show based on the trigger controller.addListener(() { final cursorPos = controller.selection.baseOffset; @@ -299,6 +299,17 @@ class FlutterMentionsState extends State { _showSuggestions = val != -1; _selectedMention = val == -1 ? null : lengthMap[val]; }); + } else { + setState(() { + _showSuggestions = false; + }); + } + +// when focus has been removed form textField, hide suggestions + if ((widget.focusNode?.hasFocus) ?? false) { + setState(() { + _showSuggestions = false; + }); } }); From d0ad925be792d41b1e87fe6679f05b6c949f7ce3 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Mon, 24 Aug 2020 12:26:03 +0500 Subject: [PATCH 6/8] hide suggrestions on unfocus ++ --- lib/src/mention_view.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index a57ea56..8830667 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -306,10 +306,12 @@ class FlutterMentionsState extends State { } // when focus has been removed form textField, hide suggestions - if ((widget.focusNode?.hasFocus) ?? false) { - setState(() { - _showSuggestions = false; - }); + if (widget.focusNode != null) { + if (widget.focusNode.hasFocus == false) { + setState(() { + _showSuggestions = false; + }); + } } }); From 7c350b7b225979dba520cfe26c863b8837ce64ee Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Mon, 24 Aug 2020 12:34:52 +0500 Subject: [PATCH 7/8] Update mention_view.dart fix focusNode issue --- lib/src/mention_view.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index 8830667..1ccf0f1 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -305,7 +305,10 @@ class FlutterMentionsState extends State { }); } -// when focus has been removed form textField, hide suggestions + + }); + + // when focus has been removed form textField, hide suggestions if (widget.focusNode != null) { if (widget.focusNode.hasFocus == false) { setState(() { @@ -313,7 +316,6 @@ class FlutterMentionsState extends State { }); } } - }); super.initState(); } From 681972bc64c7b92a24e04f418aada3b3c13ae517 Mon Sep 17 00:00:00 2001 From: Hafeez Ahmed Date: Wed, 28 Jul 2021 09:03:13 +0500 Subject: [PATCH 8/8] maxLines nullable --- lib/src/mention_view.dart | 42 +++++++-------------------------------- pubspec.lock | 6 +++--- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index 3441255..3e04662 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -52,10 +52,6 @@ class FlutterMentions extends StatefulWidget { this.onSuggestionVisibleChanged, }) : super(key: key); -<<<<<<< HEAD - /// text - final String defaultText; -======= final bool hideSuggestionList; /// default text for the Mention Input. @@ -63,7 +59,6 @@ class FlutterMentions extends StatefulWidget { /// Triggers when the suggestion list visibility changed. final Function(bool)? onSuggestionVisibleChanged; ->>>>>>> upstream/master /// List of Mention that the user is allowed to triggered final List mentions; @@ -147,7 +142,7 @@ class FlutterMentions extends StatefulWidget { final bool enableSuggestions; /// {@macro flutter.widgets.editableText.maxLines} - final int maxLines; + final int? maxLines; /// {@macro flutter.widgets.editableText.minLines} final int? minLines; @@ -297,16 +292,8 @@ class FlutterMentionsState extends State { return data; } -<<<<<<< HEAD - controller.text = widget.defaultText; - - // setup a listener to figure out which suggestions to show based on the trigger - controller.addListener(() { - final cursorPos = controller.selection.baseOffset; -======= void addMention(Map value, [Mention? list]) { final selectedMention = _selectedMention!; ->>>>>>> upstream/master setState(() { _selectedMention = null; @@ -351,20 +338,6 @@ class FlutterMentionsState extends State { final val = lengthMap.indexWhere((element) { _pattern = widget.mentions.map((e) => e.trigger).join('|'); -<<<<<<< HEAD - setState(() { - _showSuggestions = val != -1; - _selectedMention = val == -1 ? null : lengthMap[val]; - }); - } else { - setState(() { - _showSuggestions = false; - }); - } - - - }); -======= return element.end == cursorPos && element.str.toLowerCase().contains(RegExp(_pattern)); }); @@ -411,16 +384,15 @@ class FlutterMentionsState extends State { controller!.addListener(suggestionListerner); controller!.addListener(inputListeners); ->>>>>>> upstream/master // when focus has been removed form textField, hide suggestions - if (widget.focusNode != null) { - if (widget.focusNode.hasFocus == false) { - setState(() { - _showSuggestions = false; - }); - } + if (widget.focusNode != null) { + if (widget.focusNode!.hasFocus == false) { + setState(() { + showSuggestions.value = false; + }); } + } super.initState(); } diff --git a/pubspec.lock b/pubspec.lock index af9486f..e3a34de 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.5.0" boolean_selector: dependency: transitive description: @@ -99,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.0" stack_trace: dependency: transitive description: @@ -134,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.2.19" typed_data: dependency: transitive description: