onTap doesn't work on ListWheelScrollView children items - Flutter

789

I solved the problem. I hope is helpful.

  1. create a int variable in State class.

class _MenuWheelState extends State { int _vIndiceWheel;

  1. in the Function onSelectedItemChanged of the ListWheelScrollView set the variable:

    onSelectedItemChanged: (ValueChanged) { setState(() { _vIndiceWheel = ValueChanged; }); },

  2. create a GestureDetecture and put the ListWheelScrollView inside:

    GestureDetector( child: ListWheelScrollView(...

  3. 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(); }, ...

Share:
789
Author by

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, 2022

Comments

  • Pars 19 minutes

    I'm trying to make a list of items using ListWheelScrollView and I want to have the ability of tapping on items but it seems onTap 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.