diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 7b93e5da60..5683e11553 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -841,7 +841,7 @@ class SimpleDialog extends StatelessWidget { ), child: DefaultTextStyle( style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6!, - child: Semantics(namesRoute: true, child: title), + child: Semantics(namesRoute: label == null, child: title), ), ); } @@ -879,6 +879,8 @@ class SimpleDialog extends StatelessWidget { if (label != null) dialogChild = Semantics( + scopesRoute: true, + explicitChildNodes: true, namesRoute: true, label: label, child: dialogChild, diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index 212c499716..38b92f9476 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -1377,6 +1377,48 @@ void main() { semantics.dispose(); }); + testWidgets('SimpleDialog does not introduce additional node', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(platform: TargetPlatform.android), + home: Material( + child: Builder( + builder: (BuildContext context) { + return Center( + child: ElevatedButton( + child: const Text('X'), + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return const SimpleDialog( + title: Text('Title'), + semanticLabel: 'label', + ); + }, + ); + }, + ), + ); + }, + ), + ), + ), + ); + + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + // A scope route is not focusable in accessibility service. + expect(semantics, includesNodeWith( + label: 'label', + flags: [SemanticsFlag.namesRoute, SemanticsFlag.scopesRoute], + )); + + semantics.dispose(); + }); + testWidgets('Dismissible.confirmDismiss defers to an AlertDialog', (WidgetTester tester) async { final GlobalKey _scaffoldKey = GlobalKey(); final List dismissedItems = [];