computeSemanticsInformation method

  1. @override
void computeSemanticsInformation(
  1. List<InlineSpanSemanticsInformation> collector, {
  2. Locale? inheritedLocale,
  3. bool inheritedSpellOut = false,
})
override

Walks the InlineSpan tree and accumulates a list of InlineSpanSemanticsInformation objects.

This method should not be directly called. Use getSemanticsInformation instead.

PlaceholderSpans in the tree will be represented with a InlineSpanSemanticsInformation.placeholder value.

Implementation

@override
void computeSemanticsInformation(
  List<InlineSpanSemanticsInformation> collector, {
  ui.Locale? inheritedLocale,
  bool inheritedSpellOut = false,
}) {
  assert(debugAssertIsValid());
  final ui.Locale? effectiveLocale = locale ?? inheritedLocale;
  final bool effectiveSpellOut = spellOut ?? inheritedSpellOut;

  if (text != null) {
    final int textLength = semanticsLabel?.length ?? text!.length;
    collector.add(InlineSpanSemanticsInformation(
      text!,
      stringAttributes: <ui.StringAttribute>[
        if (effectiveSpellOut && textLength > 0)
          ui.SpellOutStringAttribute(range: TextRange(start: 0, end: textLength)),
        if (effectiveLocale != null && textLength > 0)
          ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: textLength)),
      ],
      semanticsLabel: semanticsLabel,
      recognizer: recognizer,
    ));
  }
  final List<InlineSpan>? children = this.children;
  if (children != null) {
    for (final InlineSpan child in children) {
      if (child is TextSpan) {
        child.computeSemanticsInformation(
          collector,
          inheritedLocale: effectiveLocale,
          inheritedSpellOut: effectiveSpellOut,
        );
      } else {
        child.computeSemanticsInformation(collector);
      }
    }
  }
}