Created
August 7, 2023 22:48
-
-
Save Piinks/4332b96783a89d9c6bbd13c5038a0795 to your computer and use it in GitHub Desktop.
Intercepting mouse scrolling when nesting scroll views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/gestures.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(), | |
body: ListView.builder( | |
itemCount: 30, | |
itemBuilder: (_, int index) { | |
return SizedBox( | |
height: 300, | |
child: Center( | |
child: Listener( | |
onPointerSignal: (event) { | |
// Claims the pointer signal when the inner ListView does | |
// not, prevents the outer from claiming it. | |
GestureBinding.instance.pointerSignalResolver.register( | |
event, | |
(event) {}, | |
); | |
}, | |
child: Container( | |
height: 200, | |
width: 200, | |
color: Colors.purple[100], | |
child: ListView.builder( | |
itemCount: 20, | |
itemBuilder: (_, int index) => Text('Index $index'), | |
) | |
), | |
), | |
), | |
); | |
} | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment