From d8d04980f6e56e1e2ae68420cb23b6d669c6bf52 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Wed, 18 Nov 2026 18:17:12 +0100 Subject: [PATCH 1/2] [material_ui] Expose modal barrier dismiss semantics for Drawer on Android Fixes https://github.com/flutter/flutter/issues/195050 DrawerController previously excluded the drawer scrim from the semantics tree on Android via platformHasBackButton. Flutter updated ModalBarrier to include the dismiss barrier on Android for Switch Access, but DrawerController's custom scrim was not updated. This removes the obsolete Android exclusion and sets excluding directly to !widget.drawerBarrierDismissible, allowing Android Switch Access users to dismiss the modal drawer without selecting a destination. --- packages/material_ui/lib/src/drawer.dart | 12 +- .../drawer_barrier_semantics_android.yaml | 3 + packages/material_ui/test/drawer_test.dart | 177 ++++++++---------- 3 files changed, 81 insertions(+), 111 deletions(-) create mode 100644 packages/material_ui/pending_changelogs/drawer_barrier_semantics_android.yaml diff --git a/packages/material_ui/lib/src/drawer.dart b/packages/material_ui/lib/src/drawer.dart index 7070dfdc06a7..884b3e59a9c9 100644 --- a/packages/material_ui/lib/src/drawer.dart +++ b/packages/material_ui/lib/src/drawer.dart @@ -727,15 +727,6 @@ class DrawerControllerState extends State with SingleTickerPro return const SizedBox.shrink(); } } else { - final bool platformHasBackButton = switch (defaultTargetPlatform) { - TargetPlatform.android => true, - TargetPlatform.iOS || - TargetPlatform.macOS || - TargetPlatform.fuchsia || - TargetPlatform.linux || - TargetPlatform.windows => false, - }; - final Color scrimColor = widget.scrimColor ?? DrawerTheme.of(context).scrimColor ?? @@ -757,8 +748,7 @@ class DrawerControllerState extends State with SingleTickerPro children: [ BlockSemantics( child: ExcludeSemantics( - // On Android, the back button is used to dismiss a modal. - excluding: platformHasBackButton, + excluding: !widget.drawerBarrierDismissible, child: GestureDetector( onTap: widget.drawerBarrierDismissible ? close : null, child: Semantics( diff --git a/packages/material_ui/pending_changelogs/drawer_barrier_semantics_android.yaml b/packages/material_ui/pending_changelogs/drawer_barrier_semantics_android.yaml new file mode 100644 index 000000000000..74930adc0479 --- /dev/null +++ b/packages/material_ui/pending_changelogs/drawer_barrier_semantics_android.yaml @@ -0,0 +1,3 @@ +changelog: | + - Exposes modal barrier dismiss semantics for `Drawer` on Android to support Switch Access. +version: patch diff --git a/packages/material_ui/test/drawer_test.dart b/packages/material_ui/test/drawer_test.dart index 448c02294fe0..7181358bd25b 100644 --- a/packages/material_ui/test/drawer_test.dart +++ b/packages/material_ui/test/drawer_test.dart @@ -130,37 +130,34 @@ void main() { expect(find.text('Archive'), findsNothing); }); - testWidgets( - 'Drawer dismiss barrier has label', - (WidgetTester tester) async { - final semantics = SemanticsTester(tester); - await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer()))); + testWidgets('Drawer dismiss barrier has label', (WidgetTester tester) async { + final semantics = SemanticsTester(tester); + await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer()))); - final ScaffoldState state = tester.firstState(find.byType(Scaffold)); - state.openDrawer(); + final ScaffoldState state = tester.firstState(find.byType(Scaffold)); + state.openDrawer(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); - expect( - semantics, - includesNodeWith( - label: const DefaultMaterialLocalizations().modalBarrierDismissLabel, - actions: [SemanticsAction.tap], - ), - ); + expect( + semantics, + includesNodeWith( + label: const DefaultMaterialLocalizations().modalBarrierDismissLabel, + actions: [SemanticsAction.tap], + ), + ); - semantics.dispose(); - }, - variant: const TargetPlatformVariant({ - TargetPlatform.iOS, - TargetPlatform.macOS, - }), - ); + semantics.dispose(); + }, variant: TargetPlatformVariant.all()); - testWidgets('Drawer dismiss barrier has no label', (WidgetTester tester) async { + testWidgets('Drawer dismiss barrier has no label when drawerBarrierDismissible is false', ( + WidgetTester tester, + ) async { final semantics = SemanticsTester(tester); - await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer()))); + await tester.pumpWidget( + const MaterialApp(home: Scaffold(drawerBarrierDismissible: false, drawer: Drawer())), + ); final ScaffoldState state = tester.firstState(find.byType(Scaffold)); state.openDrawer(); @@ -179,7 +176,7 @@ void main() { ); semantics.dispose(); - }, variant: TargetPlatformVariant.only(TargetPlatform.android)); + }, variant: TargetPlatformVariant.all()); testWidgets('Drawer tap test', (WidgetTester tester) async { final scaffoldKey = GlobalKey(); @@ -1308,69 +1305,64 @@ void main() { expect(find.byType(Drawer), findsExactly(0)); }); - testWidgets( - 'Dismissible Drawer includes button in semantic tree', - (WidgetTester tester) async { - final semantics = SemanticsTester(tester); - final scaffoldKey = GlobalKey(); + testWidgets('Dismissible Drawer includes button in semantic tree', (WidgetTester tester) async { + final semantics = SemanticsTester(tester); + final scaffoldKey = GlobalKey(); - await tester.pumpWidget( - MaterialApp( - home: Builder( - builder: (BuildContext context) { - return Scaffold(key: scaffoldKey, drawer: const Drawer()); - }, - ), + await tester.pumpWidget( + MaterialApp( + home: Builder( + builder: (BuildContext context) { + return Scaffold(key: scaffoldKey, drawer: const Drawer()); + }, ), - ); + ), + ); - // Open the drawer. - scaffoldKey.currentState!.openDrawer(); - await tester.pump(const Duration(milliseconds: 100)); + // Open the drawer. + scaffoldKey.currentState!.openDrawer(); + await tester.pump(const Duration(milliseconds: 100)); - expect(semantics, includesNodeWith(actions: [SemanticsAction.tap])); - expect(semantics, includesNodeWith(label: 'Dismiss')); + expect(semantics, includesNodeWith(actions: [SemanticsAction.tap])); + expect(semantics, includesNodeWith(label: 'Dismiss')); - semantics.dispose(); - }, - variant: const TargetPlatformVariant({ - TargetPlatform.iOS, - TargetPlatform.macOS, - }), - ); + semantics.dispose(); + }, variant: TargetPlatformVariant.all()); - testWidgets( - 'Dismissible Drawer barrier is hidden from semantics on Android (back button is used to dismiss)', - (WidgetTester tester) async { - final semantics = SemanticsTester(tester); - final scaffoldKey = GlobalKey(); + testWidgets('Non-dismissible Drawer barrier is hidden from semantics', ( + WidgetTester tester, + ) async { + final semantics = SemanticsTester(tester); + final scaffoldKey = GlobalKey(); - await tester.pumpWidget( - MaterialApp( - home: Builder( - builder: (BuildContext context) { - return Scaffold(key: scaffoldKey, drawer: const Drawer(), body: Container()); - }, - ), + await tester.pumpWidget( + MaterialApp( + home: Builder( + builder: (BuildContext context) { + return Scaffold( + key: scaffoldKey, + drawerBarrierDismissible: false, + drawer: const Drawer(), + ); + }, ), - ); + ), + ); - // Open the drawer. - scaffoldKey.currentState!.openDrawer(); - await tester.pump(const Duration(milliseconds: 100)); + // Open the drawer. + scaffoldKey.currentState!.openDrawer(); + await tester.pump(const Duration(milliseconds: 100)); - expect( - semantics, - isNot( - includesNodeWith(actions: [SemanticsAction.tap, SemanticsAction.focus]), - ), - ); - expect(semantics, isNot(includesNodeWith(label: 'Dismiss'))); + expect( + semantics, + isNot( + includesNodeWith(actions: [SemanticsAction.tap, SemanticsAction.focus]), + ), + ); + expect(semantics, isNot(includesNodeWith(label: 'Dismiss'))); - semantics.dispose(); - }, - variant: TargetPlatformVariant.only(TargetPlatform.android), - ); + semantics.dispose(); + }, variant: TargetPlatformVariant.all()); testWidgets('Drawer can be configured as not dismissible', (WidgetTester tester) async { await tester.pumpWidget( @@ -1530,28 +1522,13 @@ void main() { // Test barrier semantics. final semantics = SemanticsTester(tester); - final expectBarrierExcluded = defaultTargetPlatform == TargetPlatform.android; - - if (expectBarrierExcluded) { - expect( - semantics, - isNot( - includesNodeWith( - label: localizations.modalBarrierDismissLabel, - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - ), - ); - } else { - expect( - semantics, - includesNodeWith( - label: localizations.modalBarrierDismissLabel, - actions: [SemanticsAction.tap], - ), - ); - } - + expect( + semantics, + includesNodeWith( + label: localizations.modalBarrierDismissLabel, + actions: [SemanticsAction.tap], + ), + ); semantics.dispose(); } From 4c9c489b368a64368ae1c9777b725a89d9b67cc8 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Wed, 18 Nov 2026 18:51:53 +0100 Subject: [PATCH 2/2] [material_ui] Use DefaultMaterialLocalizations.modalBarrierDismissLabel in drawer tests Avoid hardcoding 'Dismiss' string in drawer barrier semantics tests. --- packages/material_ui/test/drawer_test.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/material_ui/test/drawer_test.dart b/packages/material_ui/test/drawer_test.dart index 7181358bd25b..41d8330ae31b 100644 --- a/packages/material_ui/test/drawer_test.dart +++ b/packages/material_ui/test/drawer_test.dart @@ -1324,7 +1324,10 @@ void main() { await tester.pump(const Duration(milliseconds: 100)); expect(semantics, includesNodeWith(actions: [SemanticsAction.tap])); - expect(semantics, includesNodeWith(label: 'Dismiss')); + expect( + semantics, + includesNodeWith(label: const DefaultMaterialLocalizations().modalBarrierDismissLabel), + ); semantics.dispose(); }, variant: TargetPlatformVariant.all()); @@ -1359,7 +1362,10 @@ void main() { includesNodeWith(actions: [SemanticsAction.tap, SemanticsAction.focus]), ), ); - expect(semantics, isNot(includesNodeWith(label: 'Dismiss'))); + expect( + semantics, + isNot(includesNodeWith(label: const DefaultMaterialLocalizations().modalBarrierDismissLabel)), + ); semantics.dispose(); }, variant: TargetPlatformVariant.all());