Fixes dialog title announce twice (#90075)
This commit is contained in:
@@ -499,7 +499,9 @@ class AlertDialog extends StatelessWidget {
|
||||
child: DefaultTextStyle(
|
||||
style: titleTextStyle ?? dialogTheme.titleTextStyle ?? theme.textTheme.headline6!,
|
||||
child: Semantics(
|
||||
namesRoute: label == null,
|
||||
// For iOS platform, the focus always lands on the title.
|
||||
// Set nameRoute to false to avoid title being announce twice.
|
||||
namesRoute: label == null && theme.platform != TargetPlatform.iOS,
|
||||
container: true,
|
||||
child: title,
|
||||
),
|
||||
@@ -843,17 +845,15 @@ class SimpleDialog extends StatelessWidget {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
|
||||
String? label = semanticLabel;
|
||||
if (title == null) {
|
||||
switch (theme.platform) {
|
||||
case TargetPlatform.macOS:
|
||||
case TargetPlatform.iOS:
|
||||
break;
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
label = semanticLabel ?? MaterialLocalizations.of(context).dialogLabel;
|
||||
}
|
||||
switch (theme.platform) {
|
||||
case TargetPlatform.macOS:
|
||||
case TargetPlatform.iOS:
|
||||
break;
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
label ??= MaterialLocalizations.of(context).dialogLabel;
|
||||
}
|
||||
|
||||
// The paddingScaleFactor is used to adjust the padding of Dialog
|
||||
@@ -874,7 +874,9 @@ class SimpleDialog extends StatelessWidget {
|
||||
child: DefaultTextStyle(
|
||||
style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6!,
|
||||
child: Semantics(
|
||||
namesRoute: label == null,
|
||||
// For iOS platform, the focus always lands on the title.
|
||||
// Set nameRoute to false to avoid title being announce twice.
|
||||
namesRoute: label == null && theme.platform != TargetPlatform.iOS,
|
||||
container: true,
|
||||
child: title,
|
||||
),
|
||||
|
||||
@@ -1319,54 +1319,6 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('AlertDialog widget contains route semantics from title for iOS', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.iOS),
|
||||
home: Material(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
child: const Text('X'),
|
||||
onPressed: () {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return const AlertDialog(
|
||||
title: Text('Title'),
|
||||
content: Text('Y'),
|
||||
actions: <Widget>[],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(semantics, isNot(includesNodeWith(
|
||||
label: 'Title',
|
||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||
)));
|
||||
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(semantics, includesNodeWith(
|
||||
label: 'Title',
|
||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||
));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/78229.
|
||||
testWidgets('AlertDialog has correct semantics for content in iOS', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
@@ -1400,7 +1352,6 @@ void main() {
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 5,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||
label: 'title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
@@ -1569,7 +1520,6 @@ void main() {
|
||||
// node 4.
|
||||
TestSemantics(
|
||||
id: 5,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||
label: 'title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user