Writing Accessibility Tests for Flutter Apps
How to catch accessibility problems before your users do: semantics, widget tests, Flutter's built-in accessibility guidelines, text scaling checks, and the manual testing no automated test can replace.
Accessibility is one of those things every team agrees is important, and very few teams test. It usually gets checked once, by hand, shortly before a release. Then a refactor quietly removes a label, a new button ends up too small to tap, and nobody notices until a user who relies on a screen reader can't send a payment.
The fix is to treat accessibility like any other behaviour of your app: write tests for it. Flutter makes this surprisingly easy, because accessibility information is part of the widget tree you're already testing.
This post covers how I approach it: what Flutter's semantics are, how to test them, which built-in checks you get for free, and where manual testing still matters.
Why This Matters to Me
Accessibility has been part of my work for years. During my time at Virtusa, I worked on several accessibility-enabled mobile apps across different technologies:
- Virtusa CheckIn, a Flutter time-entry app used internally to capture daily effort, built with support for VoiceOver on iOS and TalkBack on Android.
- Virtusa REPS, a React Native app for tracking employees' digital reputation at work, with VoiceOver and TalkBack support across both platforms.
- The Bloomin' Brands restaurant apps for Outback Steakhouse, Carrabba's Italian Grill and Bonefish Grill, built with Xamarin, where we followed iOS and Android accessibility guidelines to meet WCAG requirements.
Working across Flutter, React Native and Xamarin taught me that the tools change, but the questions stay the same. Can a screen reader user understand this screen? Can they reach and operate every control? Does the layout survive large text?
Today, as Lead Mobile Developer at Kix, I work on accessibility in a live Swedish payments app built with Flutter. That includes:
- Screen reader support, adding semantics labels, roles and announcements so VoiceOver and TalkBack users can use the app.
- Large text support, making sure screens still work at the larger system font sizes.
- Contrast and tap targets, fixing colour contrast and button sizes, and making sure information doesn't rely on colour alone.
- Automated accessibility tests, using widget tests and Flutter's built-in accessibility guidelines.
In a payments app, accessibility matters even more. If someone can't confirm the amount or reach the "Send" button, they can't pay. That's why the examples in this post use a send-money screen.
The difference with Flutter is how much of this you can verify automatically. You can find more about my projects in the Projects section of my LinkedIn profile.
How Flutter Exposes Accessibility: Semantics
Screen readers like VoiceOver and TalkBack don't see your pixels. They read a separate semantics tree that Flutter builds alongside your widget tree. Each node in it describes something meaningful: a label, a role (button, header, text field), a state (enabled, checked, selected), and the actions available (tap, long press, scroll).
Many Material and Cupertino widgets add semantics for you. An ElevatedButton is announced as a button, and a Text widget is read aloud. Problems usually appear when you build custom UI, or use icons and images without text:
// ❌ A screen reader announces this as just "button", with no clue what it does
IconButton(
onPressed: onSend,
icon: const Icon(Icons.send),
)
// ✅ Screen readers now announce the tooltip: "Send money, button"
IconButton(
onPressed: onSend,
icon: const Icon(Icons.send),
tooltip: 'Send money',
)
The main tools for shaping the semantics tree are:
| Tool | Use it when |
|---|---|
Semantics(label: ..., button: true, ...) | A custom widget needs a label, role, or state |
semanticsLabel on Text | The spoken version should differ from what's displayed |
semanticLabel on Icon and Image | An icon or image carries meaning |
ExcludeSemantics / excludeFromSemantics | Something is purely decorative |
MergeSemantics | Several widgets should be read as one item, such as a list row |
Once you know these, writing tests for them is straightforward.
Step 1: Test Labels and Roles
Flutter's testWidgets lets you find widgets by their accessibility label, and check the semantics of any node.
Take a balance card from a payments app. Visually it shows 1 250,00 kr, but a screen reader may read that awkwardly, so we give it a clear spoken label:
class BalanceCard extends StatelessWidget {
const BalanceCard({super.key, required this.amount});
final String amount;
@override
Widget build(BuildContext context) {
return Semantics(
label: 'Balance: $amount kronor',
excludeSemantics: true, // replace the children's semantics with our label
child: Column(
children: [
const Text('Balance'),
Text('$amount kr'),
],
),
);
}
}
The test checks exactly what a screen reader user would hear:
testWidgets('balance card is read as one clear sentence', (tester) async {
final handle = tester.ensureSemantics();
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: BalanceCard(amount: '1 250,00'))),
);
expect(find.bySemanticsLabel('Balance: 1 250,00 kronor'), findsOneWidget);
handle.dispose();
});
For interactive widgets, check the role, state, and actions too, not just the label. containsSemantics only compares the properties you list, which keeps tests focused:
testWidgets('send button is a labelled, enabled, tappable button', (tester) async {
final handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: IconButton(
onPressed: () {},
icon: const Icon(Icons.send),
tooltip: 'Send money',
),
),
),
);
expect(
tester.getSemantics(find.byTooltip('Send money')),
containsSemantics(
tooltip: 'Send money',
isButton: true,
isEnabled: true,
hasTapAction: true,
),
);
handle.dispose();
});
Notice the test uses tooltip, not label. This is easy to get wrong: an IconButton's tooltip is exposed in the semantics tree as a separate tooltip property. Screen readers announce it and Flutter's labelling checks accept it, but find.bySemanticsLabel('Send money') won't find the button. Use find.byTooltip for these instead.
tester.ensureSemantics() makes sure the semantics tree is built during the test. Recent Flutter versions enable semantics in widget tests by default, but calling it explicitly makes the test's intent obvious, and the handle must be disposed at the end.
A useful habit: in widget tests, find interactive widgets by what a user hears (find.bySemanticsLabel or find.byTooltip) rather than by find.byKey or find.byIcon. If your test can't find the button by its spoken name, a screen reader user may not be able to either.
Step 2: Use Flutter's Built-In Accessibility Guidelines
Flutter ships with ready-made accessibility checks that scan the whole screen. This is the best value for effort in this post, because one test covers every widget on the page:
testWidgets('send money screen meets accessibility guidelines', (tester) async {
final handle = tester.ensureSemantics();
await tester.pumpWidget(const MaterialApp(home: SendMoneyScreen()));
// Tap targets are at least 48x48 on Android...
await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
// ...and at least 44x44 on iOS
await expectLater(tester, meetsGuideline(iOSTapTargetGuideline));
// Every tappable element has a label
await expectLater(tester, meetsGuideline(labeledTapTargetGuideline));
// Text has enough contrast against its background
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
When one fails, the error message names the offending widget and what's wrong with it, for example a tap target that's only 32 pixels tall, or a button without a label.
I'd add a test like this for every main screen in the app. They're cheap to write, and they catch the most common accessibility regressions automatically.
Step 3: Test Large Text
Many people increase the system font size on their phones. If your layout only works at the default size, text gets cut off, overflows, or overlaps.
In a widget test, you can set the text scale and pump the screen at several sizes. If a Row or Column overflows, Flutter reports an error and the test fails:
void main() {
for (final scale in [1.0, 1.5, 2.0]) {
testWidgets('send money screen fits at ${scale}x text size', (tester) async {
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.linear(scale),
),
child: child!,
),
home: const SendMoneyScreen(),
),
);
// Any RenderFlex overflow fails the test automatically.
expect(find.text('Send money'), findsWidgets);
});
}
}
It's also worth running this at a small screen size, since large text on a small phone is where layouts break first. tester.view.physicalSize lets you set the test screen size, and addTearDown(tester.view.reset) restores it afterwards.
Step 4: Check State Changes and Reading Order
Some accessibility bugs only appear when something changes. A few things worth testing:
- Errors are announced. When a form shows "Insufficient balance", a screen reader user needs to hear it. Wrapping the message in
Semantics(liveRegion: true, ...)tells the screen reader to announce it when it appears, and a test can check that the error text is present in the semantics tree after submitting the form. - Disabled states are exposed. A disabled "Send" button should be reported as disabled, not just greyed out visually.
containsSemantics(isEnabled: false)checks that. - Headers are marked. Section titles wrapped in
Semantics(header: true, ...)let screen reader users jump between sections.containsSemantics(isHeader: true)verifies it. - Reading order makes sense. Screen readers usually follow layout order, but complex layouts with
Stackor custom positioning can read in a strange order.Semantics(sortKey: OrdinalSortKey(1), ...)controls it explicitly.
Step 5: See the Semantics Tree for Yourself
Before writing tests for a screen, it helps to see what a screen reader sees. Turn on the semantics debugger temporarily:
MaterialApp(
showSemanticsDebugger: true,
home: const SendMoneyScreen(),
)
This replaces your UI with an overlay showing each semantics node and its label. Missing labels and oddly grouped elements become obvious straight away. The Flutter DevTools widget inspector can also show semantics information for a selected widget.
Step 6: Run It in CI
Accessibility tests are ordinary widget tests, so they run with everything else:
flutter test
Run them on every pull request in your CI pipeline. That's the whole point: an accessibility regression should fail the build just like any other bug, instead of being discovered after release.
What Automated Tests Can't Catch
Automated tests catch a lot, but not everything. They can confirm a button has a label, but not whether the label is helpful. "Button 3" passes every test and helps nobody.
So I still test by hand before major releases:
- Use VoiceOver on iOS and TalkBack on Android for real. Complete the app's main flows, such as signing in and sending money, without looking at the screen.
- Try the largest system text size and the bold text setting.
- Use platform tools: the Accessibility Inspector in Xcode, and Google's Accessibility Scanner app on Android.
- Check colour use: information like errors or a selected state shouldn't rely on colour alone.
- Test with a switch device or keyboard if your app might be used that way.
The goal is for automated tests to handle the repetitive checks, leaving manual testing for the things that need human judgment.
A Practical Checklist
| Check | How |
|---|---|
| Interactive elements have meaningful labels | find.bySemanticsLabel, find.byTooltip, labeledTapTargetGuideline |
| Correct roles and states | containsSemantics(isButton: ..., isEnabled: ...) |
| Tap targets are big enough | androidTapTargetGuideline, iOSTapTargetGuideline |
| Text is readable | textContrastGuideline |
| Layout survives large text | Pump at 1.5x and 2x with TextScaler.linear |
| Errors and updates are announced | Semantics(liveRegion: true) |
| Decorative content is hidden | ExcludeSemantics, excludeFromSemantics: true |
| Real-world usability | Manual VoiceOver and TalkBack testing |
Wrapping Up
Accessibility is easiest to keep when it's protected by tests. In Flutter, the semantics tree is right there in your widget tests, the built-in guidelines cover the most common problems in a few lines, and text-scaling tests catch layout bugs before your users do.
Having built accessibility-enabled apps in Flutter, React Native and Xamarin, and now working on accessibility in a live payments app, my advice is the same for any team: start small. Add one guidelines test to your most important screen today. Then add label checks for its key buttons. Accessibility stops being a pre-release scramble and becomes something your test suite protects on every commit.
Thanks for reading! If you're working on accessibility in your Flutter apps, I'd love to hear what's worked for your team.
Written by
Niluka Bandara
Lead Mobile Developer in Stockholm, building Flutter apps for fintech and payments.