Commit e0f3001f authored by Collin Jackson's avatar Collin Jackson Committed by GitHub

Fix physics with NestedScrollView (#11326)

* Fix physics with NestedScrollView

* Review feedback
parent 1f08bda3
......@@ -135,7 +135,9 @@ class _NestedScrollViewState extends State<NestedScrollView> {
return new CustomScrollView(
scrollDirection: widget.scrollDirection,
reverse: widget.reverse,
physics: new ClampingScrollPhysics(parent: widget.physics),
physics: widget.physics != null
? widget.physics.applyTo(const ClampingScrollPhysics())
: const ClampingScrollPhysics(),
controller: _coordinator._outerController,
slivers: widget._buildSlivers(context, _coordinator._innerController, _coordinator.hasScrolledBody),
);
......
......@@ -6,7 +6,21 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget buildTest({ ScrollController controller, String title: 'TTTTTTTT' }) {
class _CustomPhysics extends ClampingScrollPhysics {
const _CustomPhysics({ ScrollPhysics parent }) : super(parent: parent);
@override
_CustomPhysics applyTo(ScrollPhysics ancestor) {
return new _CustomPhysics(parent: buildParent(ancestor));
}
@override
Simulation createBallisticSimulation(ScrollMetrics position, double dragVelocity) {
return new ScrollSpringSimulation(spring, 1000.0, 1000.0, 1000.0);
}
}
Widget buildTest({ ScrollController controller, String title:'TTTTTTTT' }) {
return new MediaQuery(
data: const MediaQueryData(),
child: new Scaffold(
......@@ -288,4 +302,28 @@ void main() {
expect(tester.renderObject<RenderBox>(find.byType(AppBar)).size.height, 200.0);
});
testWidgets('NestedScrollViews with custom physics', (WidgetTester tester) async {
await tester.pumpWidget(new MediaQuery(
data: const MediaQueryData(),
child: new NestedScrollView(
physics: const _CustomPhysics(),
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
const SliverAppBar(
floating: true,
title: const Text('AA'),
),
];
},
body: new Container(),
)));
expect(find.text('AA'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 500));
final Offset point1 = tester.getCenter(find.text('AA'));
await tester.dragFrom(point1, const Offset(0.0, 200.0));
await tester.pump(const Duration(milliseconds: 20));
final Offset point2 = tester.getCenter(find.text('AA'));
expect(point1.dy, greaterThan(point2.dy));
});
}
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