CustomSpanBuilder class

A class 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.

Constructors

CustomSpanBuilder({required List<Definition> definitions, ParserOptions parserOptions = const ParserOptions(), TextStyle? style, TextStyle? matchStyle, bool preventBlocking = false})
Creates a CustomSpanBuilder that builds a TextSpan based on definitions.

Properties

built bool
Whether the most recent call to build caused a build of spans.
no setter
definitions List<Definition>
Definitions that specify rules for parsing, appearance and actions.
final
hashCode int
The hash code for this object.
no setterinherited
matchStyle TextStyle?
The default text style for matched strings.
final
parsed bool
Whether the most recent call to build caused text parsing.
no setter
parserOptions ParserOptions
The options for RegExp that configure how regular expressions are treated.
final
preventBlocking bool
Whether to use an isolate for parsing to avoid blocking of the UI.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
span TextSpan
no setter
style TextStyle?
The text style for strings that did not match any match patterns.
final

Methods

build({required String text, CustomSpanBuilder? oldBuilder}) Future<TextSpan>
Builds a TextSpan based on definitions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
spanText() String
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited