diff --git a/packages/flutter/lib/src/widgets/scroll_activity.dart b/packages/flutter/lib/src/widgets/scroll_activity.dart index b3c4fae257..af629b017f 100644 --- a/packages/flutter/lib/src/widgets/scroll_activity.dart +++ b/packages/flutter/lib/src/widgets/scroll_activity.dart @@ -563,7 +563,7 @@ class BallisticScrollActivity extends ScrollActivity { /// and returns true if the overflow was zero. @protected bool applyMoveTo(double value) { - return delegate.setPixels(value) == 0.0; + return delegate.setPixels(value).abs() < precisionErrorTolerance; } void _end() { diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index 692fda12c9..da5400071d 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -2444,6 +2444,53 @@ void main() { await tester.pumpWidget(buildFrame(physics: const _CustomPhysics())); expect(position.pixels, 0.0); }); + + testWidgets("NestedScrollView doesn't crash due to precision error", (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/63825 + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: NestedScrollView( + floatHeaderSlivers: true, + headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) => [ + const SliverAppBar( + expandedHeight: 250.0, + ), + ], + body: CustomScrollView( + physics: const BouncingScrollPhysics(), + slivers: [ + SliverPadding( + padding: const EdgeInsets.all(8.0), + sliver: SliverFixedExtentList( + itemExtent: 48.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return ListTile( + title: Text('Item $index'), + ); + }, + childCount: 30, + ), + ), + ), + ], + ), + ), + ), + )); + + // Scroll to bottom + await tester.fling(find.text('Item 3'), const Offset(0.0, -250.0), 10000.0); + await tester.pumpAndSettle(); + + // Fling down for AppBar to show + await tester.drag(find.text('Item 29'), const Offset(0.0, 250 - 133.7981622869321)); + + // Fling up to trigger ballistic activity + await tester.fling(find.text('Item 25'), const Offset(0.0, -50.0), 4000.0); + await tester.pumpAndSettle(); + }); } class TestHeader extends SliverPersistentHeaderDelegate {