jumpTo during a user drag shouldn't assert (#8384)

Fixes #8380
This commit is contained in:
Adam Barth 2017-02-23 19:08:27 -08:00 committed by GitHub
parent 718859ad8d
commit 6a9ea16e9f
2 changed files with 58 additions and 2 deletions

View File

@ -629,8 +629,11 @@ class DragScrollActivity extends ScrollActivity {
@override
Notification createScrollEndNotification(AbstractScrollState scrollable) {
assert(_lastDetails is DragEndDetails);
return new ScrollEndNotification(scrollable: scrollable, dragDetails: _lastDetails);
// We might not have DragEndDetails yet if we're being called from beginActivity.
return new ScrollEndNotification(
scrollable: scrollable,
dragDetails: _lastDetails is DragEndDetails ? _lastDetails : null
);
}
@override

View File

@ -115,4 +115,57 @@ void main() {
expect(log, equals(<String>['Massachusetts']));
log.clear();
});
testWidgets('Can jumpTo during drag', (WidgetTester tester) async {
final List<Type> log = <Type>[];
final ScrollController controller = new ScrollController();
await tester.pumpWidget(new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
log.add(notification.runtimeType);
return false;
},
child: new ListView(
controller: controller,
children: kStates.map<Widget>((String state) {
return new Container(
height: 200.0,
child: new Text(state),
);
}).toList(),
),
));
expect(log, isEmpty);
TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0));
await gesture.moveBy(const Offset(0.0, -100.0));
expect(log, equals(<Type>[
ScrollStartNotification,
UserScrollNotification,
ScrollUpdateNotification,
]));
log.clear();
await tester.pump();
controller.jumpTo(550.0);
expect(controller.offset, equals(550.0));
expect(log, equals(<Type>[
ScrollEndNotification,
UserScrollNotification,
ScrollStartNotification,
ScrollUpdateNotification,
ScrollEndNotification,
]));
log.clear();
await tester.pump();
await gesture.moveBy(const Offset(0.0, -100.0));
expect(controller.offset, equals(550.0));
expect(log, isEmpty);
});
}