Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListWheelScrollView children do not recognize onTap()

Tags:

flutter

dart

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'
   ),
 ),
],
);
like image 965
JoseMelendez Avatar asked Feb 26 '19 17:02

JoseMelendez


1 Answers

Last month, Michael Lang (Cilestal) published a new clickable_list_wheel_widget package.

Behavior:

  • When you click on the selected item, onItemTapCallback is called on the ClickableListWheelScrollView
  • When you click on another item, 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,
        ),
      ),
    );
  }
}
like image 84
Thierry Avatar answered Sep 27 '22 22:09

Thierry