preBuilder property

CustomSpanBuilder? preBuilder
final

A builder function to build a TextSpan to which styles and gesture actions are applied.

The example below displays "KISS" and "Keep It Simple, Stupid!" in bold, and additionally applies a colour to capital letters contained in them.

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

This is optional. If specified, the function is called first to build a TextSpan, and then another parsing is performed in CustomText itself against the plain text converted from the built span, followed by a rebuild. Check how much it affects the performance of your app if you choose to use this.

Note that CustomSpanBuilder ignores values passed to most parameters of definitions. See its document for details.

Implementation

final CustomSpanBuilder? preBuilder;