CustomSpanBuilder constructor

CustomSpanBuilder({
  1. required List<Definition> definitions,
  2. ParserOptions parserOptions = const ParserOptions(),
  3. TextStyle? style,
  4. TextStyle? matchStyle,
  5. bool preventBlocking = false,
})

Creates a CustomSpanBuilder that builds a TextSpan based on definitions.

This builder is basically used with CustomText, although it is also possible to use it independently. The example below makes "KISS" and "Keep It Simple, Stupid!" bold, and additionally applies a colour to capital letters contained in them.

CustomText(
  'KISS is an acronym for "Keep It Simple, Stupid!".',
  preBuilder: CustomSpanBuilder(
    definitions: [
      const TextDefinition(
        matcher: PatternMatcher('KISS|Keep.+Stupid!'),
        matchStyle: TextStyle(fontWeight: FontWeight.bold),
      ),
    ],
  ),
  definitions: const [
    TextDefinition(
      matcher: PatternMatcher('[A-Z]'),
      matchStyle: TextStyle(color: Colors.red),
    ),
  ],
)

The usage is similar to CustomText. However, there is an important difference that gesture actions specified in definitions are deactivated in this builder. Exceptionally, mouseCursor is not deactivated if the builder is used independently without being used with CustomText.

Implementation

CustomSpanBuilder({
  required this.definitions,
  this.parserOptions = const ParserOptions(),
  this.style,
  this.matchStyle,
  this.preventBlocking = false,
}) : _spansBuilder = SpansBuilder(
        settings: SpansBuilderSettings(
          definitions: definitions,
          style: style,
          matchStyle: matchStyle,
        ),
      );