Skip to content

Commit 2eedd1b

Browse files
committed
add multi_trigger_autocomplete_plus
1 parent 21c6561 commit 2eedd1b

35 files changed

+3106
-69
lines changed

lib/screens/common_widgets/env_trigger_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart';
2+
import 'package:multi_trigger_autocomplete_plus/multi_trigger_autocomplete.dart';
33
import 'package:extended_text_field/extended_text_field.dart';
44
import 'env_regexp_span_builder.dart';
55
import 'env_trigger_options.dart';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## 1.0.2
2+
3+
- Added `AutocompleteNoTrigger` to display autocomplete suggestions without requiring any trigger character or string.
4+
5+
## 1.0.1
6+
7+
- Made `triggerEnd` customizable instead of using a hardcoded space (`' '`).
8+
- Enhanced the handling of triggers that share a common prefix, such as `{` and `{{`, ensuring that the correct trigger is identified and processed.
9+
10+
## 1.0.0
11+
12+
- Fixed `FieldView` focus getting lost on clicking the `OptionsView` on non-mobile platforms.
13+
- Fixed `RangeError` when `textEditingValue.selection.isInvalid`.
14+
[#11](https://github.com/xsahil03x/multi_trigger_autocomplete/issues/11)
15+
- Fixed `AutocompleteTrigger` not getting triggered when the text is a multi-line
16+
string. [#12](https://github.com/xsahil03x/multi_trigger_autocomplete/issues/12)
17+
18+
## 0.1.1
19+
20+
- Fixed Readme.
21+
22+
## 0.1.0
23+
24+
- Initial release.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Sahil Kumar
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
# Multi Trigger Autocomplete Plus
2+
3+
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/MIT) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/xsahil03x/multi_trigger_autocomplete/blob/master/LICENSE) [![Dart CI](https://github.com/xsahil03x/multi_trigger_autocomplete/workflows/multi_trigger_autocomplete/badge.svg)](https://github.com/xsahil03x/multi_trigger_autocomplete/actions) [![CodeCov](https://codecov.io/gh/xsahil03x/multi_trigger_autocomplete/branch/master/graph/badge.svg)](https://codecov.io/gh/xsahil03x/multi_trigger_autocomplete) [![Version](https://img.shields.io/pub/v/multi_trigger_autocomplete.svg)](https://pub.dartlang.org/packages/multi_trigger_autocomplete)
4+
5+
> This is a fork from [multi_trigger_autocomplete](https://pub.dev/packages/multi_trigger_autocomplete)
6+
7+
A flutter widget to add trigger based autocomplete functionality to your app.
8+
9+
**Show some ❤️ and star the repo to support the project**
10+
11+
<p>
12+
<img src="https://github.com/DenserMeerkat/multi_trigger_autocomplete_plus/blob/master/asset/package_demo.gif?raw=true" alt="An animated image of the MultiTriggerAutocomplete" height="400"/>
13+
</p>
14+
15+
## Improvements
16+
17+
This fork includes the following improvements over the original package:
18+
19+
- **AutocompleteNoTrigger**: A Special trigger which allows allows autcomplete suggestions without a trigger character/string.
20+
- **Enhanced Customization**: Allows customization of `triggerEnd` instead of using a hardcoded space (`' '`).
21+
- **Prefix Triggers Handling**: Correctly identifies and handles triggers that share a common prefix, such as `{` and `{{`.
22+
23+
## Installation
24+
25+
Add the following to your `pubspec.yaml` and replace `[version]` with the latest version:
26+
27+
```yaml
28+
dependencies:
29+
multi_trigger_autocomplete_plus: ^[version]
30+
```
31+
32+
## Usage
33+
34+
To use this package you must first wrap your top most widget
35+
with [Portal](https://pub.dev/documentation/flutter_portal/latest/flutter_portal/Portal-class.html) as this package
36+
uses [flutter_portal](https://pub.dev/packages/flutter_portal)
37+
to show the options view.
38+
39+
(Credits to: [Remi Rousselet](https://github.com/rrousselGit))
40+
41+
> `Portal`, is the equivalent of [Overlay].
42+
>
43+
> This widget will need to be inserted above the widget that needs to render
44+
> _under_ your overlays.
45+
>
46+
> If you want to display your overlays on the top of _everything_, a good place
47+
> to insert that `Portal` is above `MaterialApp`:
48+
>
49+
> ```dart
50+
> Portal(
51+
> child: MaterialApp(
52+
> ...
53+
> )
54+
> );
55+
> ```
56+
>
57+
> (works for `CupertinoApp` too)
58+
>
59+
> This way `Portal` will render above everything. But you could place it
60+
> somewhere else to change the clip behavior.
61+
62+
Import the package:
63+
64+
```dart
65+
import 'package:multi_trigger_autocomplete_plus/multi_trigger_autocomplete.dart';
66+
```
67+
68+
Use the widget:
69+
70+
```dart
71+
MultiTriggerAutocomplete(
72+
optionsAlignment: OptionsAlignment.topStart,
73+
autocompleteTriggers: [
74+
// Add the triggers you want to use for autocomplete
75+
AutocompleteTrigger(
76+
trigger: '@',
77+
optionsViewBuilder: (context, autocompleteQuery, controller) {
78+
return MentionAutocompleteOptions(
79+
query: autocompleteQuery.query,
80+
onMentionUserTap: (user) {
81+
final autocomplete = MultiTriggerAutocomplete.of(context);
82+
return autocomplete.acceptAutocompleteOption(user.id);
83+
},
84+
);
85+
},
86+
),
87+
AutocompleteTrigger(
88+
trigger: '#',
89+
optionsViewBuilder: (context, autocompleteQuery, controller) {
90+
return HashtagAutocompleteOptions(
91+
query: autocompleteQuery.query,
92+
onHashtagTap: (hashtag) {
93+
final autocomplete = MultiTriggerAutocomplete.of(context);
94+
return autocomplete
95+
.acceptAutocompleteOption(hashtag.name);
96+
},
97+
);
98+
},
99+
),
100+
AutocompleteTrigger(
101+
trigger: ':',
102+
optionsViewBuilder: (context, autocompleteQuery, controller) {
103+
return EmojiAutocompleteOptions(
104+
query: autocompleteQuery.query,
105+
onEmojiTap: (emoji) {
106+
final autocomplete = MultiTriggerAutocomplete.of(context);
107+
return autocomplete.acceptAutocompleteOption(
108+
emoji.char,
109+
// Passing false as we don't want the trigger [:] to
110+
// get prefixed to the option in case of emoji.
111+
keepTrigger: false,
112+
);
113+
},
114+
);
115+
},
116+
),
117+
],
118+
// Add the text field widget you want to use for autocomplete
119+
fieldViewBuilder: (context, controller, focusNode) {
120+
return Padding(
121+
padding: const EdgeInsets.all(8.0),
122+
child: ChatMessageTextField(
123+
focusNode: focusNode,
124+
controller: controller,
125+
),
126+
);
127+
},
128+
),
129+
```
130+
131+
## Demo
132+
133+
| Mention Autocomplete | Hashtag Autocomplete | Emoji Autocomplete |
134+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
135+
| <img src="https://github.com/DenserMeerkat/multi_trigger_autocomplete_plus/blob/master/asset/mention_demo.gif?raw=true" height="400" alt="Mention Autocomplete"/> | <img src="https://github.com/DenserMeerkat/multi_trigger_autocomplete_plus/blob/master/asset/hashtag_demo.gif?raw=true" height="400" alt="Hashtag Autocomplete"/> | <img src="https://github.com/DenserMeerkat/multi_trigger_autocomplete_plus/blob/master/asset/emoji_demo.gif?raw=true" height="400" alt="Emoji Autocomplete"/> |
136+
137+
## Customization
138+
139+
### MultiTriggerAutocomplete
140+
141+
```dart
142+
MultiTriggerAutocomplete(
143+
// Defines the autocomplete trigger that will be used to match the
144+
// text.
145+
autocompleteTriggers: autocompleteTriggers,
146+
147+
// Defines the alignment of the options view relative to the
148+
// fieldView.
149+
//
150+
// By default, the options view is aligned to the bottom of the
151+
// fieldView.
152+
optionsAlignment: OptionsAlignment.topStart,
153+
154+
// Defines the width to make the options as a multiple of the width
155+
// of the fieldView.
156+
//
157+
// Setting this to 1 makes the options view width matches the width
158+
// of the fieldView.
159+
//
160+
// Use null to remove this constraint.
161+
optionsWidthFactor: 1.0,
162+
163+
// Defines the duration of the debounce period for the
164+
// [TextEditingController].
165+
//
166+
// This is the time between the last character typed and the matching
167+
// is performed.
168+
debounceDuration: const Duration(milliseconds: 350),
169+
170+
// Defines the initial value to set in the internal
171+
// [TextEditingController].
172+
//
173+
// This value will be ignored if [TextEditingController] is provided.
174+
initialValue: const TextEditingValue(text: 'Hello'),
175+
176+
// Defines the [TextEditingController] that will be used for the
177+
// fieldView.
178+
//
179+
// If this parameter is provided, then [focusNode] must also be
180+
// provided.
181+
textEditingController: TextEditingController(text: 'Hello'),
182+
183+
// Defines the [FocusNode] that will be used for the fieldView.
184+
//
185+
// If this parameter is provided, then [textEditingController] must
186+
// also be provided.
187+
focusNode: FocusNode(),
188+
189+
// Defines the fieldView that will be used to input the text.
190+
//
191+
// By default, a [TextFormField] is used.
192+
fieldViewBuilder: (context, controller, focusNode) {
193+
return TextField(
194+
controller: controller,
195+
focusNode: focusNode,
196+
);
197+
},
198+
),
199+
```
200+
201+
### AutocompleteTrigger
202+
203+
```dart
204+
AutocompleteTrigger(
205+
// The trigger string/character that will be used to trigger the
206+
// autocomplete.
207+
trigger: '@',
208+
209+
// The trigger end string/character that will be used to determine
210+
// the end of the trigger.
211+
// By default, it's a space.
212+
triggerEnd: ' ',
213+
214+
// If true, the [trigger] should only be recognised at
215+
// the start of the input text.
216+
//
217+
// valid example: "@luke hello"
218+
// invalid example: "Hello @luke"
219+
triggerOnlyAtStart: false,
220+
221+
// If true, the [trigger] should only be recognised after
222+
// a space.
223+
//
224+
// valid example: "@luke", "Hello @luke"
225+
// invalid example: "Hello@luke"
226+
triggerOnlyAfterSpace: true,
227+
228+
// A minimum number of characters can be provided to only show
229+
// suggestions after the user has input enough characters.
230+
//
231+
// example:
232+
// "Hello @l" -> Shows zero suggestions.
233+
// "Hello @lu" -> Shows suggestions for @lu.
234+
minimumRequiredCharacters: 2,
235+
236+
// The options view builder is used to build the options view
237+
// that will be shown when the [trigger] is detected.
238+
optionsViewBuilder: (context, autocompleteQuery, controller) {
239+
return MentionAutocompleteOptions(
240+
query: autocompleteQuery.query,
241+
onMentionUserTap: (user) {
242+
// Accept the autocomplete option.
243+
final autocomplete = MultiTriggerAutocomplete.of(context);
244+
return autocomplete.acceptAutocompleteOption(user.id);
245+
},
246+
);
247+
},
248+
)
249+
```
250+
251+
### AutocompleteNoTrigger
252+
253+
Can be used to display autocomplete suggestions without requiring a trigger string or character.
254+
255+
```dart
256+
AutocompleteNoTrigger(
257+
// A minimum number of characters can be provided to only show
258+
// suggestions after the user has input enough characters.
259+
minimumRequiredCharacters: 2,
260+
261+
// The options view builder is used to build the options view
262+
// that will be shown when the [trigger] is detected.
263+
optionsViewBuilder: (context, autocompleteQuery, controller) {
264+
return MentionAutocompleteOptions(
265+
query: autocompleteQuery.query,
266+
onMentionUserTap: (user) {
267+
// Accept the autocomplete option.
268+
final autocomplete = MultiTriggerAutocomplete.of(context);
269+
return autocomplete.acceptAutocompleteOption(user.id);
270+
271+
// Handle field unfocusing manually using a FocusNode
272+
focusNode.unfocus();
273+
},
274+
);
275+
},
276+
)
277+
```
278+
279+
## License
280+
281+
[MIT License](LICENSE)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
2.23 MB
Loading
2.25 MB
Loading
1.28 MB
Loading
6.1 MB
Loading

0 commit comments

Comments
 (0)