The children of a ListWheelScrollView do not recognize taps. How can I make the children of a ListWheelScrollView recognize taps? I think there is some kind of scrollable widget infront of the children which is preventing the children from being clicked. If I put this code inside of a listview, everything works fine, but not for a listWheelScrollView
Here's my code
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(
'List Wheel',
),
),
body: myListWheel,
),
),
);
}
Widget myListWheel = ListWheelScrollView (
itemExtent: 100,
children: <Widget>[
ListTile(
enabled: true,
onTap: () {
print('Hello, World');
},
title: Text(
'First',
),
subtitle: Text(
'this is subtitle'
),
),
ListTile(
enabled: true,
onTap: () {
print('Hello, World');
},
title: Text(
'Second',
),
subtitle: Text(
'this is a subtitle'
),
),
],
);
Last month, Michael Lang (Cilestal) published a new clickable_list_wheel_widget package.
onItemTapCallback
is called on the ClickableListWheelScrollView
onItemTapCallback
is called on the ClickableListWheelScrollView
, immediately followed by a call to onSelectedItemChanged
on the ListWheelScrollView
import 'package:flutter/material.dart';
import 'package:clickable_list_wheel_view/clickable_list_wheel_widget.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(
'List Wheel',
),
),
body: MyListWheel(),
),
),
);
}
class MyListWheel extends StatelessWidget {
final _scrollController = FixedExtentScrollController();
final double _itemHeight = 100.0;
final data = List.generate(20, (index) => 'Item $index');
@override
Widget build(BuildContext context) {
return ClickableListWheelScrollView(
scrollController: _scrollController,
itemHeight: _itemHeight,
itemCount: data.length,
onItemTapCallback: (index) {
print("onItemTapCallback index: $index");
},
child: ListWheelScrollView.useDelegate(
controller: _scrollController,
itemExtent: _itemHeight,
physics: FixedExtentScrollPhysics(),
overAndUnderCenterOpacity: 0.5,
perspective: 0.002,
onSelectedItemChanged: (index) {
print("onSelectedItemChanged index: $index");
},
childDelegate: ListWheelChildBuilderDelegate(
builder: (context, index) => ListTile(title: Text(data[index])),
childCount: data.length,
),
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With