Unverified Commit 9cb2d4d6 authored by chunhtai's avatar chunhtai Committed by GitHub

Fixed the sliver appbar to have a fixed traversal order (#65049)

parent 0bb1e573
...@@ -698,13 +698,21 @@ class _AppBarState extends State<AppBar> { ...@@ -698,13 +698,21 @@ class _AppBarState extends State<AppBar> {
appBar = Stack( appBar = Stack(
fit: StackFit.passthrough, fit: StackFit.passthrough,
children: <Widget>[ children: <Widget>[
widget.flexibleSpace, Semantics(
sortKey: const OrdinalSortKey(1.0),
explicitChildNodes: true,
child: widget.flexibleSpace,
),
Semantics(
sortKey: const OrdinalSortKey(0.0),
explicitChildNodes: true,
// Creates a material widget to prevent the flexibleSpace from // Creates a material widget to prevent the flexibleSpace from
// obscuring the ink splashes produced by appBar children. // obscuring the ink splashes produced by appBar children.
Material( child: Material(
type: MaterialType.transparency, type: MaterialType.transparency,
child: appBar, child: appBar,
), ),
),
], ],
); );
} }
......
...@@ -1643,6 +1643,77 @@ void main() { ...@@ -1643,6 +1643,77 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
label: 'Leading',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: 'Action 1',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(),
],
),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
),
],
),
],
),
],
),
],
),
],
),
ignoreRect: true,
ignoreTransform: true,
ignoreId: true,
));
semantics.dispose();
});
testWidgets('SliverAppBar with flexable space has correct semantics order', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/64922.
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
const MaterialApp(
home: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
leading: Text('Leading'),
flexibleSpace: Text('Flexible space'),
actions: <Widget>[Text('Action 1')],
),
],
),
),
);
expect(semantics, hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
...@@ -1658,6 +1729,17 @@ void main() { ...@@ -1658,6 +1729,17 @@ void main() {
), ),
], ],
), ),
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isHeader],
label: 'Flexible space',
textDirection: TextDirection.ltr,
),
],
),
],
),
TestSemantics( TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
), ),
......
...@@ -178,7 +178,11 @@ void main() { ...@@ -178,7 +178,11 @@ void main() {
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight),
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: 11, id: 12,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
children: <TestSemantics>[
TestSemantics(
id: 13,
rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0), rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0),
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isHeader, SemanticsFlag.isHeader,
...@@ -187,16 +191,24 @@ void main() { ...@@ -187,16 +191,24 @@ void main() {
label: 'Title', label: 'Title',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
],
),
TestSemantics( TestSemantics(
id: 10, id: 10,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
children: <TestSemantics>[
TestSemantics(
id: 11,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight),
label: 'Expanded title', label: 'Expanded title',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
], ],
), ),
],
),
TestSemantics( TestSemantics(
id: 12, id: 14,
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
rect: TestSemantics.fullScreen, rect: TestSemantics.fullScreen,
actions: <SemanticsAction>[SemanticsAction.scrollUp], actions: <SemanticsAction>[SemanticsAction.scrollUp],
...@@ -272,7 +284,11 @@ void main() { ...@@ -272,7 +284,11 @@ void main() {
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 56.0), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 56.0),
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: 11, id: 12,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 56.0),
children: <TestSemantics>[
TestSemantics(
id: 13,
rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0), rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0),
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isHeader, SemanticsFlag.isHeader,
...@@ -281,18 +297,26 @@ void main() { ...@@ -281,18 +297,26 @@ void main() {
label: 'Title', label: 'Title',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
],
),
// The flexible space bar still persists in the // The flexible space bar still persists in the
// semantic tree even if it is collapsed. // semantic tree even if it is collapsed.
TestSemantics( TestSemantics(
id: 10, id: 10,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 56.0),
children: <TestSemantics>[
TestSemantics(
id: 11,
rect: const Rect.fromLTRB(0.0, 36.0, 800.0, 92.0), rect: const Rect.fromLTRB(0.0, 36.0, 800.0, 92.0),
label: 'Expanded title', label: 'Expanded title',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
], ],
), ),
],
),
TestSemantics( TestSemantics(
id: 12, id: 14,
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
rect: TestSemantics.fullScreen, rect: TestSemantics.fullScreen,
actions: <SemanticsAction>[SemanticsAction.scrollUp, SemanticsAction.scrollDown], actions: <SemanticsAction>[SemanticsAction.scrollUp, SemanticsAction.scrollDown],
...@@ -324,20 +348,20 @@ void main() { ...@@ -324,20 +348,20 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
TestSemantics( TestSemantics(
id: 13, id: 15,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
label: 'Item 4', label: 'Item 4',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
TestSemantics( TestSemantics(
id: 14, id: 16,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
flags: <SemanticsFlag>[SemanticsFlag.isHidden], flags: <SemanticsFlag>[SemanticsFlag.isHidden],
label: 'Item 5', label: 'Item 5',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
TestSemantics( TestSemantics(
id: 15, id: 17,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0), rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0),
flags: <SemanticsFlag>[SemanticsFlag.isHidden], flags: <SemanticsFlag>[SemanticsFlag.isHidden],
label: 'Item 6', label: 'Item 6',
......
...@@ -985,6 +985,9 @@ void _tests() { ...@@ -985,6 +985,9 @@ void _tests() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
children: <TestSemantics>[
TestSemantics(),
TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
...@@ -996,6 +999,8 @@ void _tests() { ...@@ -996,6 +999,8 @@ void _tests() {
), ),
], ],
), ),
],
),
TestSemantics( TestSemantics(
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.scrollUp, SemanticsAction.scrollUp,
...@@ -1095,6 +1100,9 @@ void _tests() { ...@@ -1095,6 +1100,9 @@ void _tests() {
), ),
TestSemantics( TestSemantics(
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
children: <TestSemantics>[
TestSemantics(),
TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
...@@ -1111,6 +1119,8 @@ void _tests() { ...@@ -1111,6 +1119,8 @@ void _tests() {
], ],
), ),
], ],
),
],
), ignoreTransform: true, ignoreRect: true, ignoreId: true, ), ignoreTransform: true, ignoreRect: true, ignoreId: true,
)); ));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment