Unverified Commit 48d5fcab authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

evict _SliverFractionalPadding cache on constraint change (#50523)

parent f15c887c
......@@ -122,6 +122,8 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
assert(viewportFraction >= 0),
_viewportFraction = viewportFraction;
SliverConstraints _lastResolvedConstraints;
double get viewportFraction => _viewportFraction;
double _viewportFraction;
set viewportFraction(double newValue) {
......@@ -142,10 +144,12 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
}
void _resolve() {
if (_resolvedPadding != null)
if (_resolvedPadding != null && _lastResolvedConstraints == constraints)
return;
assert(constraints.axis != null);
final double paddingValue = constraints.viewportMainAxisExtent * viewportFraction;
_lastResolvedConstraints = constraints;
switch (constraints.axis) {
case Axis.horizontal:
_resolvedPadding = EdgeInsets.symmetric(horizontal: paddingValue);
......
......@@ -682,6 +682,48 @@ void main() {
}
});
testWidgets('the current item remains centered on constraint change', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/50505.
final PageController controller = PageController(
initialPage: kStates.length - 1,
viewportFraction: 0.5,
);
Widget build(Size size) {
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox.fromSize(
size: size,
child: PageView(
children: kStates.map<Widget>((String state) => Text(state)).toList(),
controller: controller,
onPageChanged: (int page) { },
),
),
),
);
}
// Verifies that the last item is centered on screen.
void verifyCentered() {
expect(
tester.getCenter(find.text(kStates.last)),
offsetMoreOrLessEquals(const Offset(400, 300)),
);
}
await tester.pumpWidget(build(const Size(300, 300)));
await tester.pumpAndSettle();
verifyCentered();
await tester.pumpWidget(build(const Size(200, 300)));
await tester.pumpAndSettle();
verifyCentered();
});
testWidgets('PageView does not report page changed on overscroll', (WidgetTester tester) async {
final PageController controller = PageController(
initialPage: kStates.length - 1,
......
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