Flutter
Accessible Views: counter and task examples
Walk through keyboard access, large text, semantics and non-replayed messages in complete counter and task examples.
Open the 1.2.5 package sources. Run the commands below from that project; adding the package to your own application does not install its example host there.
This guide follows two runnable applications: the counter and the task feature. Start with the counter: it is small enough to see the entire path from a business command to the button, displayed value, and transient message.
The examples use standalone material_ui. Ark MVP Flutter itself depends on
Flutter widgets, not on a particular design system. Accessibility does not
require a new Model type, an additional state manager, or a special MVP host.
1. Run the counter
From the package root:
cd example/app
flutter pub get
flutter run -d chrome -t ../main.dart
Open the address served by Flutter, not web/index.html as a local file.
Initially the counter is 0. Increment adds one after a short asynchronous
command. At 10, the same button offers Explain limit. Show details opens
presentation-only explanatory text; it does not submit a business command.
2. Keep the responsibilities visible
CounterUseCase owns the number and caps it at 10. CounterModel exposes a
snapshot and an increment callback, not a reference to the UseCase.
CounterPresenter prepares the number's formatted label, the busy state and
button policy. It also owns the local detailsExpanded flag. _CounterView
chooses Flutter widgets and describes their meaning to assistive technology.
A screen reader needs the same business information as the visible View, not a second business state. Do not add accessibility flags to Repository or UseCase just to describe how a button is rendered.
3. Distinguish waiting from reaching the limit
There are three cases, not two:
| Situation | Label | Action |
|---|---|---|
| Value below 10, idle | Increment | Submit increment |
| Command processing | Increment | Disabled |
| Value is 10, idle | Explain limit | Emit a message effect |
The example's ViewState therefore has separate isBusy and canIncrement
properties. In the MvpView builder, the prepared state selects the callback:
onIncrement: viewState.isBusy
? null
: viewState.canIncrement
? presenter.increment
: presenter.explainLimit,
_CounterView.onIncrement is a VoidCallback?. Passing null to FilledButton
disables the control through its normal Flutter API, including its enabled
semantics. The label stays Increment during processing. A false
canIncrement alone must not be interpreted as “the business limit was reached”:
it can also mean “wait for the current command”.
isBusy belongs to this application's example ViewState. It is not a new field
in the Ark MVP public API.
4. Make values and expansion understandable
A bare “7” gives less context than “Counter value: 7”. The View supplies that meaning while preserving the visible number:
Semantics(
label: 'Counter value',
value: viewState.valueLabel,
excludeSemantics: true,
child: Text(viewState.valueLabel),
)
excludeSemantics prevents the inner Text from contributing the same number
again. It does not hide the value: the parent explicitly provides it. This
example is English; a localized application must localize the semantic label
along with its visible copy.
The details control exposes its expanded state:
MergeSemantics(
child: Semantics(
expanded: viewState.detailsExpanded,
child: TextButton(
onPressed: onToggleDetails,
child: Text(viewState.detailsExpanded ? 'Hide details' : 'Show details'),
),
),
)
Here merging gives the expanded flag and the standard button semantics to one accessible control. Without merging, the flag may describe a parent node rather than the button. Do not copy this wrapper onto every button: standard buttons already expose their role, label, enabled state and activation action.
5. Keep controls reachable with a keyboard and large text
Use Tab and Shift+Tab to move between controls, then Enter or Space to activate buttons according to the platform's shortcuts. No pointer click or private FocusNode is required by the counter. In the task application, focus Add task, activate it, then focus the new task row and activate it to open its detail page.
The counter's body uses SingleChildScrollView around a width-constrained
Column. On a short display, or after increasing text size, content can scroll
instead of overflowing below the screen. The task list already uses ListView.
Do not clamp the user's text scale to make the original fixed layout fit.
The automated scenarios use 320 × 480 with 3× text for the counter and 320 × 568 with 3× text for tasks. These are regression cases, not a claim that every font, locale and device has been certified.
6. Deliver a message through one presentation path
CounterPresenter.explainLimit() emits CounterLimitReached. MvpView delivers
it to onEffect, which calls ScaffoldMessenger.showSnackBar in the active
context. Neither the builder nor buildViewState emits this effect.
The standalone Material SnackBar already has a semantic live region. The example does not also call a manual announcement API or wrap the message in a second live region. That would introduce a second announcement path.
Changing text scale rebuilds presentation; it must not submit the command or enqueue the previous SnackBar again. The test checks that the same SnackBar survives those rebuilds and that no second one appears after it expires. Another explicit press of Explain limit may legitimately produce a new effect.
This proves event delivery and the widget's semantic structure. It does not guarantee the exact timing, wording or number of spoken utterances on every screen reader. Those are separate platform checks.
7. Run the checks and finish device verification
From the package root, run:
flutter test test/counter_accessibility_test.dart test/task_accessibility_test.dart
Each file exercises a complete application flow in its own test isolate. Counter checks cover keyboard activation, disabled processing, the semantic value, expanded state, non-replayed messages and large-text scrolling. Task checks cover forward/reverse keyboard traversal, list/detail navigation, large-text creation and resource closure when the app is removed.
For manual verification, run the counter and then restart the host with
flutter run -d chrome -t ../ecosystem_integration.dart. Check:
- Without a mouse, every action is reachable and the focused control is visible.
- With large text, details and buttons remain reachable by scrolling.
- With VoiceOver or TalkBack on a supported device, the counter value has a meaningful name, the details button exposes expansion and the message is understandable without looking at the screen.
- Returning from task detail preserves the list and does not repeat a command.
Physical-device VoiceOver/TalkBack checks are not established by the Widget tests. They remain necessary before claiming screen-reader support for a particular application and platform. The example patterns do not certify an application's colour contrast, custom controls or entire navigation flow.