Skip to content

[flutter_test] Add a Matcher for CapturedAccessibilityAnnouncement #180057

@zemanux

Description

@zemanux

Use case

Currently, when testing announceSemantics, we retrieve a list of CapturedAccessibilityAnnouncement objects via tester.takeAnnouncements(). Verifying the content of these announcements often requires manual checks of the properties (message, textDirection, assertiveness), which can be verbose, especially for lists.

Proposal

I suggest introducing an accessibilityAnnouncement matcher (with PR #180058). This would allow developers to write cleaner and more readable tests.

Benefits

The main advantage is the ability to easily check lists of announcements using standard collection matchers.

For example, existing tests in widget_tester_test.dart or user apps often manually iterate through the list or check indices. With this matcher, we can simply use contains, orderedEquals, or containsAll.

Example Usage:

Current approach:

expect(tester.takeAnnouncements().length, 1);
expect(tester.takeAnnouncements().first.message, 'Hello');
expect(tester.takeAnnouncements().first.textDirection, TextDirection.ltr);

With proposed Matcher:

expect(
  tester.takeAnnouncements(),
  [accessibilityAnnouncement('Hello', textDirection: TextDirection.ltr)],
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our testsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions