Sub topic 2
How Flutter Describes Your UI to Assistive Technology
Prerequisites and the working model
This chapter assumes that you know basic Dart syntax, can build Flutter layouts, and have run an app on an emulator or device.
Flutter does not expose your widget tree directly to a screen reader. Instead, it builds a semantics tree. A semantics tree is a structured description of the parts of your interface that users can perceive or operate. Each useful item can have a label, role, value, state, and available actions.
Flutter sends this description to the platform accessibility service:
- TalkBack on Android
- VoiceOver on iOS
- Browser accessibility APIs on Flutter web
- Platform accessibility systems on desktop
A Text widget might produce a node with the text “Save”. An IconButton might produce a button node with the label “Save document” and an action for activation. Decorative layout objects may produce no node at all.
The semantics tree is separate from the visual layout. Two widgets that look like one control can create several nodes, while one widget can create a single node with useful information. This distinction explains why an interface can look correct but still be difficult to use with assistive technology.
From widgets to platform services
Flutter starts with widgets and render objects. Render objects that contribute accessibility information create semantics data. Flutter combines this data into a tree, then sends updates to the operating system when the tree changes.
A semantics node can contain information such as:
| Information | Example |
|---|---|
| Label | “Add to favorites” |
| Role | Button |
| State | Checked |
| Value | “4 of 10” |
| Action | Tap or increase |
The platform decides how to present this information. For example, a screen reader may announce a node as “Add to favorites, button”. Your Flutter code supplies the meaning; the platform supplies the user-facing behavior.
Built-in semantics
Many standard Material and Cupertino widgets already create useful semantics. IconButton uses its tooltip as an accessibility label. Add a tooltip when the icon's purpose is not obvious:
IconButton(
icon: const Icon(Icons.favorite_border),
tooltip: 'Add to favorites',
onPressed: _toggleFavorite,
)The callback gives the button an action. The tooltip gives that action a name. Without the tooltip, a screen reader may expose only an unlabeled button.
Custom widgets do not automatically gain the same meaning just because they respond to gestures. Inspect the semantics result rather than assuming that visual text or an icon will be announced correctly. The next step is to add missing information with the Semantics widget.
> callout note > Treat semantics as part of your user interface contract. When a control changes, check its label, role, state, and actions along with its appearance.
Inspecting the result
Use Android TalkBack or iOS VoiceOver to move through the app one semantic item at a time. Listen for missing labels, duplicated information, incorrect roles, and controls that cannot be activated. Flutter's semantics debugger can also show which areas contribute to the semantics tree during development.
Exercise
Why can a visually correct IconButton still be inaccessible to a screen reader?
Show answer
Its icon may communicate meaning visually but provide no spoken label. Supplying a tooltip gives the button a name in the semantics tree.