buildWidget method

  1. @override
BuildResult buildWidget(
  1. MathOptions options,
  2. List<BuildResult?> childBuildResults
)
override

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 numElements = 2 + body.length + middle.length;
  final a = options.fontMetrics.axisHeight.cssEm.toLpUnder(options);

  final childWidgets = List.generate(numElements, (index) {
    if (index % 2 == 0) {
      // Delimiter
      return LineElement(
        customCrossSize: (height, depth) {
          final delta = math.max(height - a, depth + a);
          final delimeterFullHeight = math.max(delta / 500 * delimiterFactor,
              2 * delta - delimiterShorfall.toLpUnder(options));
          return BoxConstraints(minHeight: delimeterFullHeight);
        },
        trailingMargin: index == numElements - 1
            ? 0.0
            : getSpacingSize(index == 0 ? AtomType.open : AtomType.rel,
                    body[(index + 1) ~/ 2].leftType, options.style)
                .toLpUnder(options),
        child: LayoutBuilderPreserveBaseline(
          builder: (context, constraints) => buildCustomSizedDelimWidget(
            index == 0
                ? leftDelim
                : index == numElements - 1
                    ? rightDelim
                    : middle[index ~/ 2 - 1],
            constraints.minHeight,
            options,
          ),
        ),
      );
    } else {
      // Content
      return LineElement(
        trailingMargin: getSpacingSize(
                body[index ~/ 2].rightType,
                index == numElements - 2 ? AtomType.close : AtomType.rel,
                options.style)
            .toLpUnder(options),
        child: childBuildResults[index ~/ 2]!.widget,
      );
    }
  }, growable: false);
  return BuildResult(
    options: options,
    widget: Line(
      children: childWidgets,
    ),
  );
}