Skip to content

Commit

Permalink
v2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazelu committed Aug 1, 2024
1 parent 61a8eca commit 2786c9d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 📥
Expand All @@ -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) {
Expand Down Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 2786c9d

Please sign in to comment.