Sub topic 11
Announcing Changes as They Happen
Assume you know basic Dart, stateful Flutter widgets, and the Semantics widget. This chapter focuses on dynamic updates such as save results, loading states, and validation messages.
Why dynamic announcements matter
A screen reader usually announces the widget that receives focus. It may not announce text that changes somewhere else on the screen. For example, a sighted user can see “Profile saved,” but a screen reader user may hear nothing after activating the Save button.
A live region is a part of the interface whose changing content should be announced by assistive technology. In Flutter, set liveRegion: true on a Semantics node that contains short status updates.
Use live regions for meaningful changes:
| Change | Useful announcement |
|---|---|
| Save completes | “Profile saved” |
| A request fails | “Could not connect. Try again.” |
| A result count changes | “12 results found” |
| A progress value changes | A selected milestone, not every tick |
Keep the region small. Do not mark an entire page as live. Frequent announcements can interrupt the user and make navigation difficult.
A live status example
This example changes a status message after the user presses a button. The semantics node has a stable place in the widget tree, but its label changes when status changes.
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: SaveDemo()));
}
class SaveDemo extends StatefulWidget {
const SaveDemo({super.key});
@override
State<SaveDemo> createState() => _SaveDemoState();
}
class _SaveDemoState extends State<SaveDemo> {
String status = 'Changes not saved';
void save() {
setState(() {
status = 'Profile saved';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Profile')),
body: Column(
children: [
Semantics(
container: true,
liveRegion: true,
label: status,
child: Text(status),
),
ElevatedButton(
onPressed: save,
child: const Text('Save'),
),
],
),
);
}
}The label is the text exposed to accessibility services. When setState changes status, Flutter rebuilds the node. The platform can then announce the new label. Exact timing and interruption behavior depend on the platform and screen reader, so test on the devices you support.
Avoiding noisy or missing announcements
A common error is rebuilding a live region on every animation frame or network progress event. Announce only useful milestones, such as “Uploading started,” “Halfway finished,” and “Upload complete.”
Another error is changing visible text without giving it semantics. If the message is decorative, exclude it. If it communicates state, make the state part of the label:
- Include the result, not only a changing icon.
- Keep messages short and specific.
- Do not repeat a message when its meaning has not changed.
- Leave the action button focused unless the user must move to an error or result.
For one-off announcements, Flutter also provides platform announcement APIs. Use those carefully because they are immediate and may interrupt speech. A live region is usually a better fit for a persistent status area.
Exercise
A search screen updates from “Searching…” to “24 results found,” but the screen reader says nothing. What change should you make?
Show answer
Put the result text in a small Semantics node with liveRegion: true, and update its label when the result count changes.