preBuilder property
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(
// This pattern is used for parsing the TextSpan built
// by preBuilder, not for the original text.
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 for the plain text converted from the built span, followed by
a rebuild. Be careful how much it affects the performance of your app.
Note that CustomSpanBuilder ignores values passed to most parameters of definitions. See its document for details.
Implementation
final CustomSpanBuilder? preBuilder;