onTap doesn't work on ListWheelScrollView children items - Flutter
I solved the problem. I hope is helpful.
- create a int variable in State class.
class _MenuWheelState extends State { int _vIndiceWheel;
in the Function onSelectedItemChanged of the ListWheelScrollView set the variable:
onSelectedItemChanged: (ValueChanged) { setState(() { _vIndiceWheel = ValueChanged; }); },
create a GestureDetecture and put the ListWheelScrollView inside:
GestureDetector( child: ListWheelScrollView(...
create onTap function at the GestureDetecture like this code:
// this is necessary if (_vIndiceWheel == null) { _vIndiceWheel = 0; }
switch (_vIndiceWheel) { case 0: { Navigator.push( context, MaterialPageRoute( builder: (context) { return YourSecondScreen(); }, ...
Pars
Web and Mobile Developer at Chista Group. Prior lead Web Developer and Mobile Developer at Fanavari Tandis. Prior Web Developer at Lifeweb co. Prior Web Developer at Caspian co. Prior lead Web Developer at Padafand IT.
Updated on December 08, 2022Comments
-
Pars 19 minutes
I'm trying to make a list of items using
ListWheelScrollView
and I want to have the ability oftapping
on items but it seemsonTap
doesn't work.Here is a simple code
List<int> numbers = [ 1, 2, 3, 4, 5 ]; ... Container( height: 200, child: ListWheelScrollView( controller: fixedExtentScrollController, physics: FixedExtentScrollPhysics(), children: numbers.map((month) { return Card( child: GestureDetector( onTap: () { print(123); }, child: Row( children: <Widget>[ Expanded( child: Padding( padding: const EdgeInsets.all(8.0), child: Text( month.toString(), style: TextStyle(fontSize: 18.0), ), )), ], ), )); }).toList(), itemExtent: 60.0, ), )
Is there something wrong with this code ? I'm pretty sure something like this will work on a
ListView
or other scrolling widgets.