SemanticsLabelBuilder class final

Builder for creating semantically correct concatenated labels with proper text direction handling and spacing.

This builder helps address the complexity of concatenating multiple text parts while handling language-specific nuances like RTL vs LTR text direction and proper spacing.

Example usage:

SemanticsLabelBuilder builder = SemanticsLabelBuilder()
  ..addPart('Hello')
  ..addPart('world');
String label = builder.build(); // "Hello world"

For multilingual text with proper RTL support:

SemanticsLabelBuilder builder = SemanticsLabelBuilder(textDirection: TextDirection.ltr)
  ..addPart('Welcome', textDirection: TextDirection.ltr)
  ..addPart('مرحبا', textDirection: TextDirection.rtl); // Arabic
String label = builder.build(); // "Welcome \u202Bمرحبا\u202C" (with Unicode embedding)

Constructors

SemanticsLabelBuilder.new({String separator = ' ', TextDirection? textDirection})
Creates a new SemanticsLabelBuilder.

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if no parts have been added to this builder.
no setter
length int
Returns the number of parts added to this builder.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
separator String
The separator used between text parts.
final
textDirection TextDirection?
The overall text direction for the concatenated label.
final

Methods

addPart(String label, {TextDirection? textDirection}) → void
Adds a text part.
build() String
Builds and returns the concatenated label from the added parts.
clear() → void
Clears all parts from this builder, allowing it to be reused.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited