combineSemanticsInfo function Null safety

List<InlineSpanSemanticsInformation> combineSemanticsInfo(
  1. List<InlineSpanSemanticsInformation> infoList
)

Combines _semanticsInfo entries where permissible.

Consecutive inline spans can be combined if their InlineSpanSemanticsInformation.requiresOwnNode return false.

Implementation

List<InlineSpanSemanticsInformation> combineSemanticsInfo(List<InlineSpanSemanticsInformation> infoList) {
  final List<InlineSpanSemanticsInformation> combined = <InlineSpanSemanticsInformation>[];
  String workingText = '';
  // TODO(ianh): this algorithm is internally inconsistent. workingText
  // never becomes null, but we check for it being so below.
  String? workingLabel;
  for (final InlineSpanSemanticsInformation info in infoList) {
    if (info.requiresOwnNode) {
      combined.add(InlineSpanSemanticsInformation(
        workingText,
        semanticsLabel: workingLabel ?? workingText,
      ));
      workingText = '';
      workingLabel = null;
      combined.add(info);
    } else {
      workingText += info.text;
      workingLabel ??= '';
      if (info.semanticsLabel != null) {
        workingLabel += info.semanticsLabel!;
      } else {
        workingLabel += info.text;
      }
    }
  }
  combined.add(InlineSpanSemanticsInformation(
    workingText,
    semanticsLabel: workingLabel,
  ));
  return combined;
}