Beginner
Accessibility in Flutter: The Semantics Widget
· 6 min read
Why Accessibility Matters
Blind or low-vision users navigate apps with their phone's screen reader (TalkBack on Android, VoiceOver on iOS); when they touch an element, it's read aloud. An app built without accessibility support becomes largely unusable for these users. The good news: most of Flutter's standard widgets (Text, Icon, ElevatedButton, etc.) produce reasonable accessibility information automatically; the problem usually shows up in custom-drawn widgets.
The Semantics Tree
Alongside the visual widget tree, Flutter maintains a separate 'semantics tree'. Each widget can add a node to it; the screen reader finds the semantics node closest to where the user touched and reads out its label, hint and value. A Text widget automatically makes its own text the label, while an Icon is usually left blank — which is why meaningful icon buttons need a manually added description.
Manual Labeling with the Semantics Widget
A custom widget drawn with a CustomPainter, or a button made of nothing but an icon, gives the screen reader no meaningful information at all. The Semantics widget fixes this:
Semantics(
button: true,
label: 'Favorilere ekle',
hint: 'Bu ürünü favori listene ekler',
child: GestureDetector(
onTap: _favorilereEkle,
child: CustomPaint(size: const Size(32, 32), painter: KalpPainter()),
),
)label briefly states what the element is ('Add to favorites'). hint is optional and describes what happens when it's tapped. button: true tells the screen reader this element is interactive (tappable), so it behaves accordingly.
excludeSemantics and mergeSemantics
Sometimes you want to suppress the semantics information coming from a subtree and use your own definition instead; excludeSemantics: true does this — it discards every semantics node the child would produce, leaving only the information from the outer Semantics widget. mergeSemantics combines several child elements (say, an icon plus a text label) into a SINGLE node for the screen reader, so the user hears them together instead of separately.
MergeSemantics(
child: Row(
children: [
const Icon(Icons.star, semanticLabel: ''),
Text('4.8 / 5'),
],
),
)Touch Target Size
Material Design recommends a touch target of at least 48x48 logical pixels; Apple's Human Interface Guidelines call for 44x44. When a small icon (say, a 16x16 Icon) is wrapped directly in a GestureDetector, it becomes hard to tap for users with limited motor control. Ready-made widgets like IconButton provide this minimum size automatically; if you're building your own tappable area, reserve at least a 48x48 region for it (with Padding if needed).
Inspecting with Flutter DevTools
In the Flutter Inspector tab of Flutter DevTools, 'Show Semantics Debugger' (or wrapping your app in a SemanticsDebugger in code) lets you visually inspect the semantics nodes on your screen and each one's label/value. It's the most practical way to quickly spot which elements are missing a label.
Things to Watch Out For
• Don't give labels to purely decorative icons that carry no information (like a divider icon); the screen reader will read out every line unnecessarily. Silence these with excludeSemantics or an empty semanticLabel. • Don't write labels that are overly long or detailed; a single sentence saying what the thing is is enough. • Don't forget color contrast (text/background) either — accessibility isn't just about screen readers, it matters for low-vision users too.
Conclusion
Flutter's standard widgets handle most of accessibility for you; the real work starts with custom-drawn widgets and icon-only buttons. Add explicit labels and hints with Semantics, combine related elements with mergeSemantics, keep touch targets at least 48x48, and check regularly with DevTools' semantics debugger.