If I create a long list in Flutter Web with a ListView.builder, I get the mouse wheel events and the PageUp/PageDown keyboard events working fine. If I specify a custom ScrollController, the PageUp/PageDown keyboard events are no longer captured. How can I fix that? Here's a simple example
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late ScrollController _controller;
@override
void initState() {
_controller = ScrollController();
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListView.builder(
itemCount: 500,
controller: _controller, // will not respond to PageUp, PageDown
itemBuilder: (BuildContext context, int i) => Text('Item $i'))),
);
}
}
If you comment out the controller: _controller
line, the PageUp/PageDown presses work.
Is this a bug? If not, what do I need to do to my custom controller to respond to PageUp/PageDown?
Thank you for your help, Tony
Aucun commentaire:
Enregistrer un commentaire