CustomText constructor

const CustomText(
  1. String text, {
  2. Key? key,
  3. required List<Definition> definitions,
  4. CustomSpanBuilder? preBuilder,
  5. ParserOptions parserOptions = const ParserOptions(),
  6. TextStyle? style,
  7. TextStyle? matchStyle,
  8. TextStyle? tapStyle,
  9. TextStyle? hoverStyle,
  10. GestureCallback? onTap,
  11. GestureCallback? onLongPress,
  12. GestureCallback? onGesture,
  13. Duration? longPressDuration,
  14. bool preventBlocking = false,
  15. StrutStyle? strutStyle,
  16. TextAlign? textAlign,
  17. TextDirection? textDirection,
  18. Locale? locale,
  19. bool? softWrap,
  20. TextOverflow? overflow,
  21. TextScaler? textScaler,
  22. int? maxLines,
  23. String? semanticsLabel,
  24. TextWidthBasis? textWidthBasis,
  25. TextHeightBehavior? textHeightBehavior,
  26. Color? selectionColor,
})

Creates a text widget that decorates substrings and enables tap, long-press and/or hover gestures on them based on flexible definitions.

This is useful for making certain portions of text such as URLs, email addresses or phone numbers clickable, or for only highlighting substrings with colours and different font settings.

CustomText(
  'URL: https://example.com/\n'
  'Email: foo@example.com\n'
  'Tel: +1-012-3456-7890',
  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),
)

Implementation

const CustomText(
  String this.text, {
  super.key,
  required this.definitions,
  this.preBuilder,
  this.parserOptions = const ParserOptions(),
  this.style,
  this.matchStyle,
  this.tapStyle,
  this.hoverStyle,
  this.onTap,
  this.onLongPress,
  this.onGesture,
  this.longPressDuration,
  this.preventBlocking = false,
  this.strutStyle,
  this.textAlign,
  this.textDirection,
  this.locale,
  this.softWrap,
  this.overflow,
  this.textScaler,
  this.maxLines,
  this.semanticsLabel,
  this.textWidthBasis,
  this.textHeightBehavior,
  this.selectionColor,
}) : spans = null;