Unverified Commit fa2d770c authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Fix SliverScrollingPersistentHeader not able to update stretchConfiguration (#112042)

parent 1fbd7ec1
......@@ -402,6 +402,11 @@ class _SliverScrollingPersistentHeader extends _SliverPersistentHeaderRenderObje
stretchConfiguration: delegate.stretchConfiguration,
);
}
@override
void updateRenderObject(BuildContext context, covariant _RenderSliverScrollingPersistentHeaderForWidgets renderObject) {
renderObject.stretchConfiguration = delegate.stretchConfiguration;
}
}
class _RenderSliverScrollingPersistentHeaderForWidgets extends RenderSliverScrollingPersistentHeader
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/src/rendering/sliver_persistent_header.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'_SliverScrollingPersistentHeader 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(
delegate: TestDelegate(
stretchConfiguration: OverScrollHeaderStretchConfiguration(
stretchTriggerOffset: stretchTriggerOffset,
),
),
)
],
),
));
}
expect(
tester.allWidgets.where((Widget w) =>
w.runtimeType.toString() == '_SliverScrollingPersistentHeader'),
isNotEmpty);
final RenderSliverScrollingPersistentHeader render = tester.allRenderObjects
.whereType<RenderSliverScrollingPersistentHeader>()
.first;
expect(render.stretchConfiguration?.stretchTriggerOffset, 20);
});
}
class TestDelegate extends SliverPersistentHeaderDelegate {
TestDelegate({this.stretchConfiguration, this.showOnScreenConfiguration});
@override
double get maxExtent => 200.0;
@override
double get minExtent => 200.0;
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(height: maxExtent);
}
@override
bool shouldRebuild(TestDelegate oldDelegate) => false;
@override
final OverScrollHeaderStretchConfiguration? stretchConfiguration;
@override
final PersistentHeaderShowOnScreenConfiguration? showOnScreenConfiguration;
}
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