Skip to content

Instantly share code, notes, and snippets.

@Piinks
Created August 7, 2023 22:48
Show Gist options
  • Save Piinks/4332b96783a89d9c6bbd13c5038a0795 to your computer and use it in GitHub Desktop.
Save Piinks/4332b96783a89d9c6bbd13c5038a0795 to your computer and use it in GitHub Desktop.
Intercepting mouse scrolling when nesting scroll views
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