addMention method
Implementation
void addMention(Map<String, dynamic> value, [Mention? list]) {
final selectedMention = _selectedMention!;
setState(() {
_selectedMention = null;
});
final _list = widget.mentions
.firstWhere((element) => selectedMention.str.contains(element.trigger));
// find the text by range and replace with the new value.
controller!.text = controller!.value.text.replaceRange(
selectedMention.start,
selectedMention.end,
"${_list.trigger}${value['display']}${widget.appendSpaceOnAdd ? ' ' : ''}",
);
if (widget.onMentionAdd != null) widget.onMentionAdd!(value);
// Move the cursor to next position after the new mentioned item.
var nextCursorPosition =
selectedMention.start + 1 + value['display']?.length as int? ?? 0;
if (widget.appendSpaceOnAdd) nextCursorPosition++;
controller!.selection =
TextSelection.fromPosition(TextPosition(offset: nextCursorPosition));
}