Skip to content

Commit 6a0e0bf

Browse files
authored
Enable explicitChildNodes for the AlertDialog content (#149130)
fixes [AlertDialog content semantics merged](flutter/flutter#147574) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, // showSemanticsDebugger: true, home: Scaffold( body: SafeArea( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ const Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Some text'), Text('More text'), ], ), Builder(builder: (BuildContext context) { return ElevatedButton( onPressed: () { showDialog<void>( context: context, builder: (BuildContext context) { return AlertDialog( title: const Text('Dialog Title'), content: const Column( children: <Widget>[ Text('Some text'), Text('More text'), ], ), actions: <Widget>[ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: const Text('Close'), ), ], ); }, ); }, child: const Text('Open Dialog'), ); }), ], ), ), ), ), ); } } ``` </details> ### Before vs After ![Screenshot 2024-05-27 at 14 59 57](https://github.com/flutter/flutter/assets/48603081/3b231a7a-db71-4dbf-bd4a-dd44a537cae8) ![Screenshot 2024-05-27 at 14 56 04](https://github.com/flutter/flutter/assets/48603081/219c1de5-ad35-49b3-a80f-4f036184e22b)
1 parent d71f4eb commit 6a0e0bf

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/flutter/lib/src/material/dialog.dart

+1
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ class AlertDialog extends StatelessWidget {
812812
style: contentTextStyle ?? dialogTheme.contentTextStyle ?? defaults.contentTextStyle!,
813813
child: Semantics(
814814
container: true,
815+
explicitChildNodes: true,
815816
child: content,
816817
),
817818
),

packages/flutter/test/material/dialog_test.dart

+19-4
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,12 @@ void main() {
17001700
theme: ThemeData(platform: TargetPlatform.iOS),
17011701
home: const AlertDialog(
17021702
title: Text('title'),
1703-
content: Text('content'),
1703+
content: Column(
1704+
children: <Widget>[
1705+
Text('some content'),
1706+
Text('more content'),
1707+
],
1708+
),
17041709
actions: <Widget>[ TextButton(onPressed: null, child: Text('action')) ],
17051710
),
17061711
),
@@ -1731,11 +1736,21 @@ void main() {
17311736
// node 4.
17321737
TestSemantics(
17331738
id: 6,
1734-
label: 'content',
1735-
textDirection: TextDirection.ltr,
1739+
children: <TestSemantics>[
1740+
TestSemantics(
1741+
id: 7,
1742+
label: 'some content',
1743+
textDirection: TextDirection.ltr,
1744+
),
1745+
TestSemantics(
1746+
id: 8,
1747+
label: 'more content',
1748+
textDirection: TextDirection.ltr,
1749+
),
1750+
],
17361751
),
17371752
TestSemantics(
1738-
id: 7,
1753+
id: 9,
17391754
flags: <SemanticsFlag>[
17401755
SemanticsFlag.isButton,
17411756
SemanticsFlag.hasEnabledState,

0 commit comments

Comments
 (0)