Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions lib/src/mention_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FlutterMentions extends StatefulWidget {
this.buildCounter,
this.scrollPhysics,
this.scrollController,
this.controller,
this.autofillHints,
this.appendSpaceOnAdd = true,
this.hideSuggestionList = false,
Expand Down Expand Up @@ -237,25 +238,18 @@ class FlutterMentions extends StatefulWidget {
/// {@macro flutter.widgets.editableText.scrollController}
final ScrollController? scrollController;

/// AnnotationEditingController for the text of the widget.
final AnnotationEditingController? controller;

/// {@macro flutter.widgets.editableText.autofillHints}
/// {@macro flutter.services.autofill.autofillHints}
final Iterable<String>? autofillHints;

@override
FlutterMentionsState createState() => FlutterMentionsState();
}

class FlutterMentionsState extends State<FlutterMentions> {
AnnotationEditingController? controller;
ValueNotifier<bool> showSuggestions = ValueNotifier(false);
LengthMap? _selectedMention;
String _pattern = '';

Map<String, Annotation> mapToAnotation() {
static Map<String, Annotation> mapToAnotation(List<Mention> mentions) {
final data = <String, Annotation>{};

// Loop over all the mention items and generate a suggestions matching list
widget.mentions.forEach((element) {
mentions.forEach((element) {
// if matchAll is set to true add a general regex patteren to match with
if (element.matchAll) {
data['${element.trigger}([A-Za-z0-9])*'] = Annotation(
Expand All @@ -270,28 +264,37 @@ class FlutterMentionsState extends State<FlutterMentions> {

element.data.forEach(
(e) => data["${element.trigger}${e['display']}"] = e['style'] != null
? Annotation(
style: e['style'],
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
markupBuilder: element.markupBuilder,
)
: Annotation(
style: element.style,
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
markupBuilder: element.markupBuilder,
),
? Annotation(
style: e['style'],
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
markupBuilder: element.markupBuilder,
) : Annotation(
style: element.style,
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
markupBuilder: element.markupBuilder,
),
);
});

return data;
}

@override
FlutterMentionsState createState() => FlutterMentionsState();
}

class FlutterMentionsState extends State<FlutterMentions> {
AnnotationEditingController? controller;
ValueNotifier<bool> showSuggestions = ValueNotifier(false);
LengthMap? _selectedMention;
String _pattern = '';

void addMention(Map<String, dynamic> value, [Mention? list]) {
final selectedMention = _selectedMention!;

Expand Down Expand Up @@ -372,9 +375,9 @@ class FlutterMentionsState extends State<FlutterMentions> {

@override
void initState() {
final data = mapToAnotation();
final data = FlutterMentions.mapToAnotation(widget.mentions);

controller = AnnotationEditingController(data);
controller = widget.controller ?? AnnotationEditingController(data);

if (widget.defaultText != null) {
controller!.text = widget.defaultText!;
Expand All @@ -400,7 +403,7 @@ class FlutterMentionsState extends State<FlutterMentions> {
void didUpdateWidget(widget) {
super.didUpdateWidget(widget);

controller!.mapping = mapToAnotation();
controller!.mapping = FlutterMentions.mapToAnotation(widget.mentions);
}

@override
Expand Down
23 changes: 15 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -73,14 +73,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -134,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -148,7 +155,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.21.0"