fix sliver fixed pinned appbar (#36333)
This commit is contained in:
parent
9c9b71a0fb
commit
b7a49c4afe
@ -476,8 +476,8 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
|
|||||||
} else {
|
} else {
|
||||||
_effectiveScrollOffset = constraints.scrollOffset;
|
_effectiveScrollOffset = constraints.scrollOffset;
|
||||||
}
|
}
|
||||||
|
excludeFromSemanticsScrolling = _effectiveScrollOffset <= constraints.scrollOffset;
|
||||||
final bool overlapsContent = _effectiveScrollOffset < constraints.scrollOffset;
|
final bool overlapsContent = _effectiveScrollOffset < constraints.scrollOffset;
|
||||||
excludeFromSemanticsScrolling = overlapsContent;
|
|
||||||
layoutChild(_effectiveScrollOffset, maxExtent, overlapsContent: overlapsContent);
|
layoutChild(_effectiveScrollOffset, maxExtent, overlapsContent: overlapsContent);
|
||||||
_childPosition = updateGeometry();
|
_childPosition = updateGeometry();
|
||||||
_lastActualScrollOffset = constraints.scrollOffset;
|
_lastActualScrollOffset = constraints.scrollOffset;
|
||||||
|
@ -6,7 +6,239 @@ import 'package:flutter/rendering.dart';
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'semantics_tester.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
testWidgets('Sliver appBars - floating and pinned - correct elevation', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Localizations(
|
||||||
|
locale: const Locale('en', 'us'),
|
||||||
|
delegates: const <LocalizationsDelegate<dynamic>>[
|
||||||
|
DefaultWidgetsLocalizations.delegate,
|
||||||
|
DefaultMaterialLocalizations.delegate,
|
||||||
|
],
|
||||||
|
child: Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: MediaQuery(
|
||||||
|
data: const MediaQueryData(),
|
||||||
|
child: CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
const SliverAppBar(
|
||||||
|
bottom: PreferredSize(
|
||||||
|
preferredSize: Size.fromHeight(28),
|
||||||
|
child: Text('Bottom'),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
floating: true,
|
||||||
|
primary: false,
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
),
|
||||||
|
SliverToBoxAdapter(child: Container(color: Colors.yellow, height: 50.0)),
|
||||||
|
SliverToBoxAdapter(child: Container(color: Colors.red, height: 50.0)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final RenderPhysicalModel renderObject = tester.renderObject<RenderPhysicalModel>(find.byType(PhysicalModel));
|
||||||
|
expect(renderObject, isNotNull);
|
||||||
|
expect(renderObject.elevation, 0.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Sliver appbars - floating and pinned - correct semantics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Localizations(
|
||||||
|
locale: const Locale('en', 'us'),
|
||||||
|
delegates: const <LocalizationsDelegate<dynamic>>[
|
||||||
|
DefaultWidgetsLocalizations.delegate,
|
||||||
|
DefaultMaterialLocalizations.delegate,
|
||||||
|
],
|
||||||
|
child: Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: MediaQuery(
|
||||||
|
data: const MediaQueryData(),
|
||||||
|
child: CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
const SliverAppBar(
|
||||||
|
title: Text('Hello'),
|
||||||
|
pinned: true,
|
||||||
|
floating: true,
|
||||||
|
expandedHeight: 200.0,
|
||||||
|
),
|
||||||
|
SliverFixedExtentList(
|
||||||
|
itemExtent: 100.0,
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(BuildContext _, int index) {
|
||||||
|
return Container(
|
||||||
|
height: 100.0,
|
||||||
|
color: index % 2 == 0 ? Colors.red : Colors.yellow,
|
||||||
|
child: Text('Tile $index'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
|
|
||||||
|
TestSemantics expectedSemantics = TestSemantics.root(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics.rootChild(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
thickness: 0,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Hello',
|
||||||
|
elevation: 0,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHeader, SemanticsFlag.namesRoute],
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
actions: <SemanticsAction>[SemanticsAction.scrollUp],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
|
scrollIndex: 0,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 0',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 1',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 2',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 3',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 4',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 5',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 6',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true));
|
||||||
|
|
||||||
|
await tester.fling(find.text('Tile 2'), const Offset(0, -600), 2000);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expectedSemantics = TestSemantics.root(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics.rootChild(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Hello',
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHeader, SemanticsFlag.namesRoute],
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
actions: <SemanticsAction>[SemanticsAction.scrollUp, SemanticsAction.scrollDown],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
|
scrollIndex: 10,
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 7',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 8',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 9',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 10',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 11',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 12',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 13',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 14',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 15',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 16',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 17',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
TestSemantics(
|
||||||
|
label: 'Tile 18',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true));
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('Sliver appbars - floating and pinned - second app bar stacks below', (WidgetTester tester) async {
|
testWidgets('Sliver appbars - floating and pinned - second app bar stacks below', (WidgetTester tester) async {
|
||||||
final ScrollController controller = ScrollController();
|
final ScrollController controller = ScrollController();
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user