Commit 649f49d4 authored by Remi Rousselet's avatar Remi Rousselet Committed by Michael Goderbauer

Swap scope with gesture (#21157)

parent 56039b4b
...@@ -524,8 +524,19 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin ...@@ -524,8 +524,19 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(position != null); assert(position != null);
// _ScrollableScope must be placed above the BuildContext returned by notificationContext
// so that we can get this ScrollableState by doing the following:
//
// ScrollNotification notification;
// Scrollable.of(notification.context)
//
// Since notificationContext is pointing to _gestureDetectorKey.context, _ScrollableScope
// must be placed above the widget using it: RawGestureDetector
Widget result = _ScrollableScope(
scrollable: this,
position: position,
// TODO(ianh): Having all these global keys is sad. // TODO(ianh): Having all these global keys is sad.
Widget result = RawGestureDetector( child: RawGestureDetector(
key: _gestureDetectorKey, key: _gestureDetectorKey,
gestures: _gestureRecognizers, gestures: _gestureRecognizers,
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
...@@ -536,9 +547,6 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin ...@@ -536,9 +547,6 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
key: _ignorePointerKey, key: _ignorePointerKey,
ignoring: _shouldIgnorePointer, ignoring: _shouldIgnorePointer,
ignoringSemantics: false, ignoringSemantics: false,
child: _ScrollableScope(
scrollable: this,
position: position,
child: widget.viewportBuilder(context, position), child: widget.viewportBuilder(context, position),
), ),
), ),
......
...@@ -82,4 +82,24 @@ void main() { ...@@ -82,4 +82,24 @@ void main() {
controller.jumpTo(400.0); controller.jumpTo(400.0);
expect(logValue, 'listener 400.0'); expect(logValue, 'listener 400.0');
}); });
testWidgets('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async {
ScrollNotification notification;
await tester.pumpWidget(NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
notification = value;
return false;
},
child: SingleChildScrollView(
child: const SizedBox(height: 1200.0)
)
));
await tester.startGesture(const Offset(100.0, 100.0));
await tester.pump(const Duration(seconds: 1));
final StatefulElement scrollableElement = find.byType(Scrollable).evaluate().first;
expect(Scrollable.of(notification.context), equals(scrollableElement.state));
});
} }
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