Skip to content
Merged
Next Next commit
Drop double precision errors that result in values < 1e-10 causing th…
…e outer scrollable to jump.
  • Loading branch information
Michal-MK committed Jan 8, 2024
commit a19c3d710932519b453bc179dd82799372cdcc20
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/nested_scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,8 @@ class _NestedScrollPosition extends ScrollPosition implements ScrollActivityDele
this,
delta,
);
if (oldPixels == newPixels) {
// Delta must have been so small we dropped it during floating point addition.
if ((oldPixels - newPixels).abs() < precisionErrorTolerance) {
// Delta is so small we can drop it.
return 0.0;
}
// Check for overscroll:
Expand Down
48 changes: 48 additions & 0 deletions packages/flutter/test/widgets/nested_scroll_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,54 @@ void main() {
expect(context.clipBehavior, equals(Clip.antiAlias));
});

testWidgets('Outer scrollable always scrolls first with BouncingScrollPhysics; fix for (#136199)', (WidgetTester tester) async {
final Key inner = UniqueKey();
final Key outer = UniqueKey();

Widget build() {
return Scaffold(
body: NestedScrollView(
key: outer,
physics: const BouncingScrollPhysics(),
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) => [
SliverToBoxAdapter(
child: Container(color: Colors.green, height: 300),
),
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverToBoxAdapter(
child: Container(
color: Colors.blue,
height: 64,
),
),
),
],
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Container(
key: inner,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <ui.Color>[Colors.black, Colors.blue],
stops: <double>[0, 1],
),
),
height: 800,
),
),
),
);
}

// Build the widget.
await tester.pumpWidget(build());

// TODO Write the actual test (fling inner scrollable, outer scrollable should not move)
});

testWidgets('NestedScrollView overscroll and release and hold', (WidgetTester tester) async {
await tester.pumpWidget(buildTest());
expect(find.text('aaa2'), findsOneWidget);
Expand Down