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

Swap scope with gesture (#21157)

parent 56039b4b
...@@ -524,21 +524,29 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin ...@@ -524,21 +524,29 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(position != null); assert(position != null);
// TODO(ianh): Having all these global keys is sad. // _ScrollableScope must be placed above the BuildContext returned by notificationContext
Widget result = RawGestureDetector( // so that we can get this ScrollableState by doing the following:
key: _gestureDetectorKey, //
gestures: _gestureRecognizers, // ScrollNotification notification;
behavior: HitTestBehavior.opaque, // Scrollable.of(notification.context)
excludeFromSemantics: widget.excludeFromSemantics, //
child: Semantics( // Since notificationContext is pointing to _gestureDetectorKey.context, _ScrollableScope
explicitChildNodes: !widget.excludeFromSemantics, // must be placed above the widget using it: RawGestureDetector
child: IgnorePointer( Widget result = _ScrollableScope(
key: _ignorePointerKey, scrollable: this,
ignoring: _shouldIgnorePointer, position: position,
ignoringSemantics: false, // TODO(ianh): Having all these global keys is sad.
child: _ScrollableScope( child: RawGestureDetector(
scrollable: this, key: _gestureDetectorKey,
position: position, gestures: _gestureRecognizers,
behavior: HitTestBehavior.opaque,
excludeFromSemantics: widget.excludeFromSemantics,
child: Semantics(
explicitChildNodes: !widget.excludeFromSemantics,
child: IgnorePointer(
key: _ignorePointerKey,
ignoring: _shouldIgnorePointer,
ignoringSemantics: false,
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