Fixes AlertDialog and SimpleDialog to not merge their content semantics (#78633)
This commit is contained in:
parent
0105c8f377
commit
00592ceb27
@ -526,7 +526,10 @@ class AlertDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: DefaultTextStyle(
|
child: DefaultTextStyle(
|
||||||
style: contentTextStyle ?? dialogTheme.contentTextStyle ?? theme.textTheme.subtitle1!,
|
style: contentTextStyle ?? dialogTheme.contentTextStyle ?? theme.textTheme.subtitle1!,
|
||||||
child: content!,
|
child: Semantics(
|
||||||
|
container: true,
|
||||||
|
child: content!,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -877,7 +880,11 @@ class SimpleDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: DefaultTextStyle(
|
child: DefaultTextStyle(
|
||||||
style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6!,
|
style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6!,
|
||||||
child: Semantics(namesRoute: label == null, child: title),
|
child: Semantics(
|
||||||
|
namesRoute: label == null,
|
||||||
|
container: true,
|
||||||
|
child: title
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1341,6 +1341,71 @@ void main() {
|
|||||||
semantics.dispose();
|
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);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData(platform: TargetPlatform.iOS),
|
||||||
|
home: const AlertDialog(
|
||||||
|
title: Text('title'),
|
||||||
|
content: Text('content'),
|
||||||
|
actions: <Widget>[ TextButton(onPressed: null, child: Text('action')) ],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(semantics, hasSemantics(TestSemantics.root(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 1,
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 2,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 3,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 4,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 5,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||||
|
label: 'title',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
// The content semantics does not merge into the semantics
|
||||||
|
// node 4.
|
||||||
|
TestSemantics(
|
||||||
|
id: 6,
|
||||||
|
label: 'content',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
id: 7,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isButton,
|
||||||
|
SemanticsFlag.hasEnabledState],
|
||||||
|
label: 'action',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
), ignoreTransform: true, ignoreId: true, ignoreRect: true));
|
||||||
|
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('AlertDialog widget always contains alert route semantics for android', (WidgetTester tester) async {
|
testWidgets('AlertDialog widget always contains alert route semantics for android', (WidgetTester tester) async {
|
||||||
final SemanticsTester semantics = SemanticsTester(tester);
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
|
|
||||||
@ -1439,6 +1504,79 @@ void main() {
|
|||||||
semantics.dispose();
|
semantics.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/78229.
|
||||||
|
testWidgets('SimpleDialog has correct semantics for title in iOS', (WidgetTester tester) async {
|
||||||
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData(platform: TargetPlatform.iOS),
|
||||||
|
home: const SimpleDialog(
|
||||||
|
title: Text('title'),
|
||||||
|
children: <Widget>[
|
||||||
|
Text('content'),
|
||||||
|
TextButton(onPressed: null, child: Text('action'))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(semantics, hasSemantics(TestSemantics.root(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 1,
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 2,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 3,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 4,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
// Title semantics does not merge into the semantics
|
||||||
|
// node 4.
|
||||||
|
TestSemantics(
|
||||||
|
id: 5,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
||||||
|
label: 'title',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
id: 6,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
id: 7,
|
||||||
|
label: 'content',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
id: 8,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isButton,
|
||||||
|
SemanticsFlag.hasEnabledState],
|
||||||
|
label: 'action',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
), ignoreTransform: true, ignoreId: true, ignoreRect: true));
|
||||||
|
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('Dismissible.confirmDismiss defers to an AlertDialog', (WidgetTester tester) async {
|
testWidgets('Dismissible.confirmDismiss defers to an AlertDialog', (WidgetTester tester) async {
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
final List<int> dismissedItems = <int>[];
|
final List<int> dismissedItems = <int>[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user