Sub topic 1
Why accessibility matters and who it serves
Prerequisites
This chapter assumes you can read basic Dart and build screens from Flutter widgets. You should know the difference between StatelessWidget and StatefulWidget. You should also be able to run an app on an emulator or a device. No accessibility knowledge is needed. The later chapters add the code. This one builds the working model behind it.
What accessibility means in an app
Accessibility means that people with different abilities and in different situations can use your app. The common shorthand is "a11y": an "a", eleven letters, and a "y".
An accessible app lets a user do these things:
- Perceive the content, whether by sight, hearing, or touch.
- Operate every control, whether by finger, keyboard, switch, or voice.
- Understand what is on screen and what will happen next.
- Rely on the app to behave the same way across devices and settings.
Platform guidelines such as WCAG (Web Content Accessibility Guidelines) organize these ideas as perceivable, operable, understandable, and robust. WCAG was written for the web. Mobile guidance from Apple and Google follows the same ideas. In this tutorial, you will use WCAG numbers (for example, a 4.5:1 contrast ratio) as targets when they apply.
Who it serves
Accessibility is often pictured as a feature for blind users only. The audience is wider. The table lists common needs, the assistive technology involved, and what your app has to provide.
| User need | Typical technology or setting | What your app must provide |
|---|---|---|
| Blind or low vision | Screen reader (TalkBack, VoiceOver), magnification | Labels, roles, and a sensible reading order |
| Low vision | Large text, bold text, high contrast | Layouts that scale, readable colors |
| Color blindness | None needed | Meaning that does not depend on color alone |
| Motor impairment | Switch control, voice control, external keyboard | Large tap targets, keyboard focus, no gesture-only actions |
| Deaf or hard of hearing | Captions, visual alerts | Text or visual equivalents for sound |
| Vestibular disorders | Reduce motion setting | Fewer or no large animations |
| Cognitive and learning differences | Simple flows, extra time | Clear wording, predictable navigation, no hard time limits |
Situational limits belong in the same table. A person holding a child in one arm has one hand available. A person on a train in bright sun cannot read pale gray text. A person with a broken wrist taps less precisely. Features built for permanent needs help in these cases too. Large tap targets, good contrast, and captions are the standard examples.
Why it matters to you as a developer
There are four practical reasons to do this work.
- Reach. The World Health Organization estimates that about 1 in 6 people worldwide lives with a significant disability. Ignoring them excludes a large share of your possible users.
- Legal exposure. Many regions require accessible digital products. Examples include the European Accessibility Act, the Americans with Disabilities Act as courts apply it to apps, and Section 508 for US government software. Check the rules that apply to your market and your customers.
- Quality for everyone. Labeled controls help voice control and UI tests. Good contrast helps outdoors. Keyboard support helps power users.
- Cost. Fixing a missing label while building a screen takes minutes. Retrofitting a finished app means touching every screen.
How Flutter fits in
Native Android and iOS apps use platform views, and each view already reports itself to the operating system. Flutter works differently. It draws every pixel itself on one canvas. To the operating system, a Flutter app would look like a single blank surface.
Flutter solves this by building a second tree next to the widget tree. This is the semantics tree. It describes the meaning of your UI (this is a button, this is a heading, this text says "Total: $12") in a form that Android's accessibility services and iOS's accessibility APIs can read. The next chapter covers it in detail. For now, hold this model:
Flutter gives you a lot for free. Standard Material and Cupertino widgets such as ElevatedButton, Checkbox, TextField, and Switch add semantics automatically. They report a role, and they report state such as checked or enabled. Text widgets expose their text as the label.
The framework cannot guess your intent in every case. It needs your help when you:
- draw custom shapes with
CustomPaint, - build tappable widgets from
GestureDetector, - use icons or images with no visible text,
- rely on swipes or long presses,
- change content without a screen change.
Most accessibility work in Flutter is closing these gaps.
A first look at the gap
Here is an icon button with no label. A sighted user sees a heart. A screen reader user hears only "button", or nothing useful.
IconButton(
icon: const Icon(Icons.favorite_border),
onPressed: _toggleFavorite,
)Adding one property fixes it. IconButton uses its tooltip as its accessibility label, and it also shows the text on long press for sighted users:
IconButton(
icon: const Icon(Icons.favorite_border),
tooltip: 'Add to favorites',
onPressed: _toggleFavorite,
)Notice that the fix also helps sighted users who do not recognize the icon. This pattern repeats often.
A custom control needs more. A GestureDetector has no role, so the system does not know it can be tapped. Wrapping it in Semantics supplies the missing information:
Semantics(
button: true,
label: 'Add to favorites',
hint: 'Saves this item to your list',
child: GestureDetector(
onTap: _toggleFavorite,
child: const Icon(Icons.favorite_border),
),
)The three properties each do a different job:
button: trueis the role. The screen reader announces "button".labelnames the control.hintdescribes the result of activating it. Keep hints short and do not repeat the label.
Prefer a built-in widget when one exists. IconButton brings focus handling, tap target size, and a ripple. The custom version brings only what you add by hand.
Common mistakes
These errors appear in most apps that were not tested with assistive tools.
- Testing only visually. An app can look perfect and be unusable with a screen reader. Run it with TalkBack or VoiceOver before you call a screen done.
- Relying on color alone. A red border for an error is invisible to some users. Pair it with an icon or message text.
- Fixed heights for text containers. Large text overflows or gets clipped.
- Small tap targets. Tiny icons are hard to hit for anyone, and for some users impossible.
- Gesture-only actions. A swipe to delete has no equivalent for a screen reader user unless you add one.
- Over-labeling. Adding
Semanticsaround widgets that already expose text can make a screen reader read the same thing twice.
How the rest of the tutorial is organized
The chapters follow the order in which problems usually appear:
- The semantics tree and how to test it with TalkBack and VoiceOver.
- Built-in semantics, the
Semanticswidget, and grouping or hiding nodes. - Visual needs: tap targets, contrast, and text scaling.
- Interaction: custom actions, live regions, platform settings, focus, and reading order.
- Automated tests, and notes on web and desktop.
Exercises
Exercise
Why does a Flutter app need a separate semantics tree, when native Android and iOS apps do not?
Show answer
Flutter draws all of its UI on a single canvas, so the operating system sees no individual views to describe. The semantics tree reports the role, label, and state of each element to the platform accessibility APIs, which TalkBack and VoiceOver then read.
Exercise
A teammate wraps a GestureDetector around an Icon to make a "share" control. A screen reader user cannot find it as a button. Name two changes that would fix it, and say which one you would prefer.
Show answer
One fix is to wrap it in Semantics(button: true, label: 'Share', ...). The other is to replace it with an IconButton that has tooltip: 'Share'. Prefer the IconButton, because it also supplies focus handling, a minimum tap target size, and visual feedback without extra code.
Exercise
Name three user groups besides blind users who benefit from accessibility work, and one app feature that helps each.
Show answer
Examples: users with low vision benefit from layouts that scale with large text. Users with motor impairment benefit from large tap targets and keyboard focus support. Users with vestibular disorders benefit from respecting the reduce motion setting. Other valid answers include captions for deaf users, and non-color cues for color-blind users.