buildWidget method
Compose Flutter widget with child widgets already built
Subclasses should override this method. This method provides a general description of the layout of this math node. The child nodes are built in prior. This method is only responsible for the placement of those child widgets accroding to the layout & other interactions.
Please ensure children works in the same order as updateChildren, computeChildOptions, and buildWidget.
Implementation
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) {
final expanded = symbol.runes.expand((code) {
final ch = String.fromCharCode(code);
return unicodeSymbols[ch]?.split('') ?? [ch];
}).toList(growable: false);
// If symbol is single code
if (expanded.length == 1) {
return makeBaseSymbol(
symbol: expanded[0],
variantForm: variantForm,
atomType: atomType,
overrideFont: overrideFont,
mode: mode,
options: options,
);
} else if (expanded.length > 1) {
if (isCombiningMark(expanded[1])) {
if (expanded[0] == 'i') {
expanded[0] = '\u0131'; // dotless i, in math and text mode
} else if (expanded[0] == 'j') {
expanded[0] = '\u0237'; // dotless j, in math and text mode
}
}
GreenNode res = this.withSymbol(expanded[0]);
for (var ch in expanded.skip(1)) {
final accent = unicodeAccents[ch];
if (accent == null) {
break;
} else {
res = AccentNode(
base: res.wrapWithEquationRow(),
label: accent,
isStretchy: false,
isShifty: true,
);
}
}
return SyntaxNode(parent: null, value: res, pos: 0).buildWidget(options);
} else {
// TODO: log a warning here.
return BuildResult(
widget: Container(
height: 0,
width: 0,
),
options: options,
italic: 0,
);
}
}