CustomTextEditingController.fromValue constructor

CustomTextEditingController.fromValue(
  1. TextEditingValue? value,
  2. {required List<TextDefinition> definitions,
  3. ParserOptions parserOptions = const ParserOptions(),
  4. TextStyle? style,
  5. TextStyle? matchStyle,
  6. TextStyle? tapStyle,
  7. TextStyle? hoverStyle,
  8. GestureCallback? onTap,
  9. GestureCallback? onLongPress,
  10. GestureCallback? onGesture,
  11. Duration? longPressDuration,
  12. Duration? debounceDuration}
)

Creates a controller for an editable text field from an initial TextEditingValue.

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,
),

Implementation

CustomTextEditingController.fromValue(
  super.value, {
  required this.definitions,
  this.parserOptions = const ParserOptions(),
  this.style,
  this.matchStyle,
  this.tapStyle,
  this.hoverStyle,
  this.onTap,
  this.onLongPress,
  this.onGesture,
  this.longPressDuration,
  this.debounceDuration,
}) : super.fromValue();