buildTextSpan static method
TextSpan
buildTextSpan(
- BuildContext? context,
- String rawText, {
- Color? color,
- double? fontSize,
- LetterSpacing? letterSpacing,
- LineHeight? lineHeight,
- FontName? fontName,
- TextDecorationEnum? textDecoration,
- List<
Effect> ? effects, - required BaseNode? node,
- required List<
VariableData> variablesOverrides, - required NullSubstitutionMode nullSubstitutionMode,
- required bool replaceVariableWithSymbol,
- bool hasMissingFont = false,
- TapGestureRecognizer? tapGestureRecognizer,
Implementation
static TextSpan buildTextSpan(
BuildContext? context,
String rawText, {
// Text properties.
Color? color,
double? fontSize,
LetterSpacing? letterSpacing,
LineHeight? lineHeight,
FontName? fontName,
TextDecorationEnum? textDecoration,
List<Effect>? effects,
// Additional properties.
required BaseNode? node,
required List<VariableData> variablesOverrides,
required NullSubstitutionMode nullSubstitutionMode,
required bool replaceVariableWithSymbol,
bool hasMissingFont = false,
TapGestureRecognizer? tapGestureRecognizer,
}) {
String characters = rawText;
final TextStyle style = switch (hasMissingFont) {
false => retrieveTextStyle(
fontSize: fontSize,
fontName: fontName,
textDecoration: textDecoration,
lineHeight: lineHeight,
letterSpacing: letterSpacing,
color: color,
effects: effects ?? (node is BlendMixin ? node.effects : const []),
),
true => TextStyle(
color: Colors.red,
fontSize: fontSize,
fontWeight: FontWeight.bold,
decorationColor: Colors.yellow,
decoration: TextDecoration.underline,
),
};
// Replace with fx symbol if required.
if (replaceVariableWithSymbol) {
final spans = characters
.splitMap(
variableSyntaxIdentifierRegex,
onMatch: (match) =>
VariableSpan(variable: characters, style: style),
onNonMatch: (text) => TextSpan(text: text, style: style),
)
.toList();
if (spans.length == 1) return spans.first;
return TextSpan(children: spans, style: style);
} else if (context != null) {
// Substitute variables.
characters = PropertyValueDelegate.substituteVariables(
rawText,
nullSubstitutionMode: nullSubstitutionMode,
scopedValues: ScopedValues.of(
context,
variablesOverrides: variablesOverrides,
),
);
}
return TextSpan(
text: characters,
style: style,
recognizer: tapGestureRecognizer,
);
}