From 2786c9dcd0de9a22a701f51950ac8bcd0bf37797 Mon Sep 17 00:00:00 2001 From: Crazelu Date: Thu, 1 Aug 2024 20:27:09 +0100 Subject: [PATCH] v2.1.1 --- CHANGELOG.md | 3 +++ README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++--- pubspec.yaml | 2 +- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fd262..8086d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,3 +36,6 @@ * Fixes issue with re-activating the search context with a trigger character immediately after adding a tag. * Removes the need for TextFields returned from FlutterTagger's builder to be wrapped with a Container to which the key from the closure must be passed. The key can now be passed directly to the TextField. +## 2.1.1 + +* Fixes issue with activating search context after updating controller's text directly. \ No newline at end of file diff --git a/README.md b/README.md index 7ab5f13..2ddae06 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency: ```yaml dependencies: - fluttertagger: ^2.1.0 + fluttertagger: ^2.1.1 ``` ## Import the package in your project 📥 @@ -40,8 +40,8 @@ FlutterTagger( //characters that can trigger a search and the styles //to be applied to their tagged results in the TextField triggerCharacterAndStyles: const { - "@": TextStyle(color: Colors.pinkAccent), - "#": TextStyle(color: Colors.blueAccent), + '@': TextStyle(color: Colors.pinkAccent), + '#': TextStyle(color: Colors.blueAccent), }, overlay: SearchResultView(), builder: (context, textFieldKey) { @@ -69,6 +69,59 @@ FlutterTagger( ) ``` +Here's how trigger a search by updating the controller directly instead of typing into a keyboard: + +```dart +FlutterTagger( + controller: flutterTaggerController, + onSearch: (query, triggerCharacter) { + //perform search + }, + //characters that can trigger a search and the styles + //to be applied to their tagged results in the TextField + triggerCharacterAndStyles: const { + '@': TextStyle(color: Colors.pinkAccent), + '#': TextStyle(color: Colors.blueAccent), + }, + overlay: SearchResultView(), + builder: (context, textFieldKey) { + //return a TextField and pass it `textFieldKey` + return TextField( + key: textFieldKey, + controller: flutterTaggerController, + suffix: IconButton( + onPressed: () { + //get formatted text from controller + String text = flutterTaggerController.formattedText; + + // append a trigger character to activate the search context + flutterTaggerController.text = text += '#'; + + // update text selection + flutterTaggerController.selection = TextSelection.fromPosition( + TextPosition(offset: flutterTaggerController.text.length), + ); + + // append other characters to trigger search + flutterTaggerController.text = text += 'f'; + + // update text selection + flutterTaggerController.selection = TextSelection.fromPosition( + TextPosition(offset: flutterTaggerController.text.length), + ); + + // then call formatTags on the controller to preserve formatting + flutterTaggerController.formatTags(); + }, + icon: const Icon( + Icons.send, + color: Colors.redAccent, + ), + ), + ); + }, + ) +``` Explore detailed example demo [here](https://github.com/Crazelu/fluttertagger/tree/main/example). diff --git a/pubspec.yaml b/pubspec.yaml index 888d362..53f357e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fluttertagger description: A Flutter package that allows for the extension of TextFields to provide tagging capabilities (user mentions, hashtags, etc). -version: 2.1.0 +version: 2.1.1 repository: https://github.com/Crazelu/fluttertagger issue_tracker: https://github.com/Crazelu/fluttertagger/issues topics: [user, mention, hashtag, tagging]