Exclude modal barrier Container in Drawer from Semantics on Android (#48841)
diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart
index 046feed..69058e2 100644
--- a/packages/flutter/lib/src/material/drawer.dart
+++ b/packages/flutter/lib/src/material/drawer.dart
@@ -542,18 +542,20 @@
child: Stack(
children: <Widget>[
BlockSemantics(
- child: GestureDetector(
+ child: ExcludeSemantics(
// On Android, the back button is used to dismiss a modal.
- excludeFromSemantics: platformHasBackButton,
- onTap: close,
- child: Semantics(
- label: MaterialLocalizations.of(context)?.modalBarrierDismissLabel,
- child: MouseRegion(
- opaque: true,
- child: Container( // The drawer's "scrim"
- color: _scrimColorTween.evaluate(_controller),
+ excluding: platformHasBackButton,
+ child: GestureDetector(
+ onTap: close,
+ child: Semantics(
+ label: MaterialLocalizations.of(context)?.modalBarrierDismissLabel,
+ child: MouseRegion(
+ opaque: true,
+ child: Container( // The drawer's "scrim"
+ color: _scrimColorTween.evaluate(_controller),
+ ),
),
- )
+ ),
),
),
),
diff --git a/packages/flutter/test/widgets/drawer_test.dart b/packages/flutter/test/widgets/drawer_test.dart
index 4087174..5fe4c4c 100644
--- a/packages/flutter/test/widgets/drawer_test.dart
+++ b/packages/flutter/test/widgets/drawer_test.dart
@@ -328,6 +328,7 @@
await tester.pump(const Duration(milliseconds: 100));
expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap]));
+ expect(semantics, includesNodeWith(label: 'Dismiss'));
semantics.dispose();
@@ -357,6 +358,7 @@
await tester.pump(const Duration(milliseconds: 100));
expect(semantics, isNot(includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap])));
+ expect(semantics, isNot(includesNodeWith(label: 'Dismiss')));
semantics.dispose();
});