Unverified Commit 2b105ac6 authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Fix ScrollPosition overscroll precision error (#127321)

## Description

This PR fixes a precision error in ~~`ClampingScrollPhysics`~~ `ScrollPosition` that leads to `StretchingOverscrollIndicator` stretching its content unexpectedly in some devices (see  https://github.com/flutter/flutter/issues/126561 where this is visible in `TabBarView` and the test added in this PR where it reproduces with a `PageView`).

~~This PR also contains a change to `nested_scroll_view.dart` because the first change (the one in `ClampingScrollPhysics`)  breaks the precision error test added by https://github.com/flutter/flutter/pull/87801.~~

## Related Issue

Fixes https://github.com/flutter/flutter/issues/126561

## Tests

Adds 1 test.
parent 5451ea6e
......@@ -368,7 +368,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
notifyListeners();
didUpdateScrollPositionBy(pixels - oldPixels);
}
if (overscroll != 0.0) {
if (overscroll.abs() > precisionErrorTolerance) {
didOverscrollBy(overscroll);
return overscroll;
}
......
......@@ -1203,4 +1203,46 @@ void main() {
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('PageView content should not be stretched on precision error', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/126561.
final PageController controller = PageController();
const double pixel6EmulatorWidth = 411.42857142857144;
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Center(
child: SizedBox(
width: pixel6EmulatorWidth,
child: PageView(
controller: controller,
physics: const PageScrollPhysics().applyTo(const ClampingScrollPhysics()),
children: const <Widget>[
Center(child: Text('First Page')),
Center(child: Text('Second Page')),
Center(child: Text('Third Page')),
],
),
),
),
));
controller.animateToPage(2, duration: const Duration(milliseconds: 300), curve: Curves.ease);
await tester.pumpAndSettle();
final Finder transformFinder = find.descendant(of: find.byType(PageView), matching: find.byType(Transform));
expect(transformFinder, findsOneWidget);
// Get the Transform widget that stretches the PageView.
final Transform transform = tester.firstWidget<Transform>(
find.descendant(
of: find.byType(PageView),
matching: find.byType(Transform),
),
);
// Check the stretch factor in the first element of the transform matrix.
expect(transform.transform.storage.first, 1.0);
});
}
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