TagTextEditingController<T> class

A controller for an editable text field that supports tagging behaviour.

This controller creates accurate representations of tags in the text field, while also allowing for a database-friendly backend format. This format can be retrieved from the controller's textInBackendFormat property. Do not use controller.text directly, as the internal format typically differs.

Additional programmatical modifications to the text that this controller manages should be done with caution, as it may interfere with the tagging behaviour. However, the controller exposes an 'insertTaggable' method that allows for the insertion of taggables at the current cursor position, bypassing the regular tagging flow, e.g. for tags that are typically not actively chosen by the user (e.g. the @here tag in Slack and Discord).

Inheritance

Constructors

TagTextEditingController.new({required FutureOr<Iterable<T>> searchTaggables(String prefix, String? query), required Future<T?> buildTaggables(FutureOr<Iterable<T>> taggables), required String toFrontendConverter(T taggable), required String toBackendConverter(T taggable), TextStyle? textStyleBuilder(BuildContext context, String prefix, T taggable)?, List<TagStyle> tagStyles = const [TagStyle()]})

Properties

buildTaggables Future<T?> Function(FutureOr<Iterable<T>> taggables)
Builds the list of taggables, if any.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchTaggables FutureOr<Iterable<T>> Function(String prefix, String? query)
Searches for taggables based on the tag prefix (e.g. '@') and query (e.g. 'Ali').
final
selection TextSelection
The currently selected range within text.
getter/setter pairinherited
tagStyles List<TagStyle>
A list of TagStyle styles that are supported by the controller.
final
text String
The current string the user is editing.
getter/setter pairinherited
textInBackendFormat String
The text formatted in backend format. Do not use controller.text directly.
no setter
textStyleBuilder TextStyle? Function(BuildContext context, String prefix, T taggable)?
A function that builds a text style for a taggable based on the tag style.
final
toBackendConverter String Function(T taggable)
Converts a taggable to a unique identifier for internal and backend use.
final
toFrontendConverter String Function(T taggable)
Converts a taggable to a string to display in the linked text field.
final
value TextEditingValue
The current value stored in this notifier.
getter/setter pairinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) TextSpan
Builds TextSpan from current editing value.
override
clear() → void
Set the value to empty.
override
clearComposing() → void
Set the composing region to an empty range.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
insertTaggable(String prefix, T taggable, int charactersToReplace) → void
Inserts a taggable into the text field at the current cursor position.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setText(String backendText, FutureOr<T?> backendToTaggable(String prefix, String backendString)) → void
Sets the initial text of the text field, converting backend strings to taggables.
taggingListeners() → void
A listener that triggers all tagging-related listeners.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited