ListWheelScrollView子级无法识别onTap()

时间:2019-02-26 17:09:26

标签: dart flutter

ListWheelScrollView的子级无法识别水龙头。如何使ListWheelScrollView的子项识别出水龙头?我认为孩子前面有某种可滚动的小部件,可防止孩子被点击。如果我将这段代码放在列表视图中,则一切正常,但不能用于listWheelScrollView

这是我的代码

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'
   ),
 ),
],
);

1 个答案:

答案 0 :(得分:1)

上个月,Michael Lang (Cilestal) 发布了一个新的clickable_list_wheel_widget package

行为:

  • 当您点击所选项目时,onItemTapCallback 会在 ClickableListWheelScrollView
  • 上被调用
  • 当您点击另一个项目时,onItemTapCallback 会在 ClickableListWheelScrollView 上被调用,紧接着是对 onSelectedItemChanged 上的 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,
        ),
      ),
    );
  }
}