Sub topic 16
Accessibility on Web and Desktop
This chapter assumes Basic Dart syntax, Flutter layout widgets, and familiarity with StatelessWidget and StatefulWidget. It also assumes you can run a Flutter app in a browser or on a desktop device.
Flutter uses the semantics tree to describe widgets to platform accessibility services. On Android and iOS, that description reaches TalkBack or VoiceOver. On the web, Flutter exposes semantics through browser accessibility structures, which screen readers can read through the browser. On Windows, macOS, and Linux, Flutter maps semantics to the desktop accessibility system.
The same Flutter code can therefore support several platforms, but the user experience is not identical.
| Platform | Important interaction | Common accessibility check |
|---|---|---|
| Web | Keyboard, browser zoom, screen reader | Test with browser screen reader and Tab |
| Desktop | Keyboard, mouse, system scaling | Test focus, shortcuts, and menus |
| Mobile | Touch and screen reader gestures | Test TalkBack or VoiceOver |
Design for web and desktop input
A web or desktop user may never touch the screen. Every important action needs a keyboard path. Buttons should be real Button widgets or widgets with usable semantics. Text fields should have labels. Focus must remain visible.
Do not use hover as the only way to reveal information. Hover does not exist for keyboard-only users and is difficult for touch users. A Tooltip can supplement a visible label, but it should not replace one.
Browser zoom and desktop display scaling can make content wider or taller. Avoid fixed widths and heights around text. Let controls wrap or scroll when necessary.
import 'package:flutter/material.dart';
void main() {
runApp(const AccessibilityExample());
}
class AccessibilityExample extends StatelessWidget {
const AccessibilityExample({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Account')),
body: Center(
child: FocusTraversalGroup(
policy: OrderedTraversalPolicy(),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
decoration: const InputDecoration(
labelText: 'Email address',
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {},
child: const Text('Continue'),
),
),
],
),
),
),
),
),
),
);
}
}The constrained width prevents an overly wide form on desktop while still allowing it to shrink in a browser window. The visible label identifies the field for sighted users and assistive technology. The button is a standard control, so it receives keyboard focus and announces its role.
Test platform-specific behavior
Test with the actual browser and desktop operating system that you support. Use Tab and Shift+Tab to move through controls. Confirm that focus is visible, the order is logical, and pressing Enter or Space activates the focused control.
Also check browser zoom at 200 percent or more and resize the window. Look for clipped text, overlapping controls, and horizontal scrolling that hides actions.
On desktop, test menus, dialogs, keyboard shortcuts, and closing behavior. A dialog should move focus into its content and return focus to the invoking control when it closes.
Exercise
Why should a Flutter web button use a real button widget instead of a GestureDetector alone?
Show answer
A real button provides a role, keyboard focus, activation behavior, and semantics that browsers and assistive technologies understand.