Unverified Commit 97e09c8a authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Fix SliverPinnedPersistentHeader, also not able to update stretchConfiguration...

Fix SliverPinnedPersistentHeader, also not able to update stretchConfiguration and showOnScreenConfiguration (#112043)
parent fa2d770c
...@@ -428,6 +428,13 @@ class _SliverPinnedPersistentHeader extends _SliverPersistentHeaderRenderObjectW ...@@ -428,6 +428,13 @@ class _SliverPinnedPersistentHeader extends _SliverPersistentHeaderRenderObjectW
showOnScreenConfiguration: delegate.showOnScreenConfiguration, showOnScreenConfiguration: delegate.showOnScreenConfiguration,
); );
} }
@override
void updateRenderObject(BuildContext context, covariant _RenderSliverPinnedPersistentHeaderForWidgets renderObject) {
renderObject
..stretchConfiguration = delegate.stretchConfiguration
..showOnScreenConfiguration = delegate.showOnScreenConfiguration;
}
} }
class _RenderSliverPinnedPersistentHeaderForWidgets extends RenderSliverPinnedPersistentHeader class _RenderSliverPinnedPersistentHeaderForWidgets extends RenderSliverPinnedPersistentHeader
......
...@@ -36,6 +36,68 @@ void main() { ...@@ -36,6 +36,68 @@ void main() {
.first; .first;
expect(render.stretchConfiguration?.stretchTriggerOffset, 20); expect(render.stretchConfiguration?.stretchTriggerOffset, 20);
}); });
testWidgets(
'_SliverPinnedPersistentHeader should update stretchConfiguration',
(WidgetTester tester) async {
for (final double stretchTriggerOffset in <double>[10.0, 20.0]) {
await tester.pumpWidget(MaterialApp(
home: CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: true,
delegate: TestDelegate(
stretchConfiguration: OverScrollHeaderStretchConfiguration(
stretchTriggerOffset: stretchTriggerOffset,
),
),
)
],
),
));
}
expect(
tester.allWidgets.where((Widget w) =>
w.runtimeType.toString() == '_SliverPinnedPersistentHeader'),
isNotEmpty);
final RenderSliverPinnedPersistentHeader render = tester.allRenderObjects
.whereType<RenderSliverPinnedPersistentHeader>()
.first;
expect(render.stretchConfiguration?.stretchTriggerOffset, 20);
});
testWidgets(
'_SliverPinnedPersistentHeader should update showOnScreenConfiguration',
(WidgetTester tester) async {
for (final double maxShowOnScreenExtent in <double>[1000, 2000]) {
await tester.pumpWidget(MaterialApp(
home: CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: true,
delegate: TestDelegate(
showOnScreenConfiguration:
PersistentHeaderShowOnScreenConfiguration(
maxShowOnScreenExtent: maxShowOnScreenExtent),
),
)
],
),
));
}
expect(
tester.allWidgets.where((Widget w) =>
w.runtimeType.toString() == '_SliverPinnedPersistentHeader'),
isNotEmpty);
final RenderSliverPinnedPersistentHeader render = tester.allRenderObjects
.whereType<RenderSliverPinnedPersistentHeader>()
.first;
expect(render.showOnScreenConfiguration?.maxShowOnScreenExtent, 2000);
});
} }
class TestDelegate extends SliverPersistentHeaderDelegate { class TestDelegate extends SliverPersistentHeaderDelegate {
......
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