Swap scope with gesture (#21157)
This commit is contained in:
committed by
Michael Goderbauer
parent
56039b4ba7
commit
649f49d4bf
@@ -524,21 +524,29 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(position != null);
|
||||
// TODO(ianh): Having all these global keys is sad.
|
||||
Widget result = RawGestureDetector(
|
||||
key: _gestureDetectorKey,
|
||||
gestures: _gestureRecognizers,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
excludeFromSemantics: widget.excludeFromSemantics,
|
||||
child: Semantics(
|
||||
explicitChildNodes: !widget.excludeFromSemantics,
|
||||
child: IgnorePointer(
|
||||
key: _ignorePointerKey,
|
||||
ignoring: _shouldIgnorePointer,
|
||||
ignoringSemantics: false,
|
||||
child: _ScrollableScope(
|
||||
scrollable: this,
|
||||
position: position,
|
||||
// _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.
|
||||
child: RawGestureDetector(
|
||||
key: _gestureDetectorKey,
|
||||
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),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -82,4 +82,24 @@ void main() {
|
||||
controller.jumpTo(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));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user