From f0801023506fcb5302b2b4b15a180a388e34cf73 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Mon, 8 Jul 2024 19:47:20 +0300 Subject: [PATCH] [Reland] - Enable `explicitChildNodes` for the `AlertDialog` content (#149597) Fixes the semantics of AlertDialog. --- packages/flutter/lib/src/material/dialog.dart | 1 + .../flutter/test/material/dialog_test.dart | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index e8049dfdba..09ac978cef 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -812,6 +812,7 @@ class AlertDialog extends StatelessWidget { style: contentTextStyle ?? dialogTheme.contentTextStyle ?? defaults.contentTextStyle!, child: Semantics( container: true, + explicitChildNodes: true, child: content, ), ), diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index 06d648eea1..8d68dfdf5f 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -1722,7 +1722,12 @@ void main() { theme: ThemeData(platform: TargetPlatform.iOS), home: const AlertDialog( title: Text('title'), - content: Text('content'), + content: Column( + children: [ + Text('some content'), + Text('more content'), + ], + ), actions: [ TextButton(onPressed: null, child: Text('action')) ], ), ), @@ -1753,11 +1758,21 @@ void main() { // node 4. TestSemantics( id: 6, - label: 'content', - textDirection: TextDirection.ltr, + children: [ + TestSemantics( + id: 7, + label: 'some content', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 8, + label: 'more content', + textDirection: TextDirection.ltr, + ), + ], ), TestSemantics( - id: 7, + id: 9, flags: [ SemanticsFlag.isButton, SemanticsFlag.hasEnabledState,