CustomTextEditingController class
A variant of TextEditingController that decorates strings in an editable text field and enables tap, long-press and/or hover gestures based on flexible definitions.
This controller is useful for making partial strings in text such as URLs, email addresses or phone numbers clickable, or for only highlighting some parts of text with colors and different font settings depending on the types of text elements.
final _controller = CustomTextEditingController(
definitions: const [
TextDefinition(matcher: UrlMatcher()),
TextDefinition(matcher: EmailMatcher()),
TextDefinition(matcher: TelMatcher()),
],
matchStyle: const TextStyle(color: Colors.indigo),
hoverStyle: const TextStyle(color: Colors.lightBlue),
onTap: (details) => launchUrlString(details.actionText),
);
...
TextField(
controller: _controller,
maxLines: null,
),
- Inheritance
-
- Object
- ChangeNotifier
- ValueNotifier<
TextEditingValue> - TextEditingController
- CustomTextEditingController
Constructors
-
CustomTextEditingController({String? text, required List<
TextDefinition> definitions, ParserOptions parserOptions = const ParserOptions(), TextStyle? style, TextStyle? matchStyle, TextStyle? tapStyle, TextStyle? hoverStyle, GestureCallback? onTap, GestureCallback? onLongPress, GestureCallback? onGesture, Duration? longPressDuration, Duration? debounceDuration}) - Creates a controller for an editable text field.
-
CustomTextEditingController.fromValue(TextEditingValue? value, {required List<
TextDefinition> definitions, ParserOptions parserOptions = const ParserOptions(), TextStyle? style, TextStyle? matchStyle, TextStyle? tapStyle, TextStyle? hoverStyle, GestureCallback? onTap, GestureCallback? onLongPress, GestureCallback? onGesture, Duration? longPressDuration, Duration? debounceDuration}) - Creates a controller for an editable text field from an initial TextEditingValue.
Properties
- debounceDuration ↔ Duration?
-
The debouncing duration after every text input action.
getter/setter pair
-
definitions
→ List<
TextDefinition> -
TextDefinitions that specify rules for parsing, appearance and
actions.
final
-
elements
→ List<
TextElement> -
The list of TextElements as a result of parsing.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hoverStyle → TextStyle?
-
The default text style used for matched strings while they are
under the mouse pointer.
final
- longPressDuration → Duration?
-
The duration before a tap is regarded as a long-press and the
onLongPress function is called.
final
- matchStyle → TextStyle?
-
The default text style for matched strings.
final
- onGesture → GestureCallback?
-
The callback function called when a gesture happens on a string.
final
- onLongPress → GestureCallback?
-
The callback function called when a matched string is long-pressed.
final
- onTap → GestureCallback?
-
The callback function called when a matched string is tapped.
final
- parserOptions → ParserOptions
-
The options for RegExp that configure how regular expressions
are treated.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selection ↔ TextSelection
-
The currently selected range within text.
getter/setter pairinherited
- style → TextStyle?
-
The text style for strings that did not match any match patterns.
final
- tapStyle → TextStyle?
-
The default text style used for tappable strings while they are
being pressed.
final
- text ↔ String
-
The current string the user is editing.
getter/setter pairinherited
- 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.
inherited
-
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
-
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
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited