Android GestureDetector在ListWheelScrollView中不工作

Android GestureDetector在ListWheelScrollView中不工作,android,flutter,dart,Android,Flutter,Dart,GestureDetector未在ListWheelScrollView中检测到onTap。 如果我包装整个ListWheel,它可以正常工作,但这样做会在点击屏幕上的任何位置时产生导航。我想让小部件检测只由ListWheelScrollView.useDelegate()返回的触摸 我在GIthub和StackOverFlow上发现了类似的问题,但当时的解决方案并没有解决我的问题。 注意:将行为赋予HitTestBehavior.translucent无效 class ListCard ext

GestureDetector未在ListWheelScrollView中检测到onTap。 如果我包装整个ListWheel,它可以正常工作,但这样做会在点击屏幕上的任何位置时产生导航。我想让小部件检测只由ListWheelScrollView.useDelegate()返回的触摸

我在GIthub和StackOverFlow上发现了类似的问题,但当时的解决方案并没有解决我的问题。 注意:将行为赋予HitTestBehavior.translucent无效

class ListCard extends StatefulWidget {
  @override
  _ListCardState createState() => _ListCardState();
}

class _ListCardState extends State<ListCard> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(left: 10.0, right: 10, top: 15),
            child: SearchBar(),
          ),
          Expanded(child: RecipeListWheel()),
        ],
      ),
    );
  }
}

class RecipeListWheel extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListWheelScrollView.useDelegate(
      diameterRatio: 1.2,
      perspective: 0.0001,
      itemExtent: 150,
      childDelegate: ListWheelChildBuilderDelegate(
          builder: (BuildContext context, int index) {
        if (index < 0 || index > 10 || index > recipeList.length - 1) {
          return null;
        }
        return Padding(
          padding: const EdgeInsets.symmetric(horizontal: 15.0),
          child: Container(
            height: 240,
            color: Colors.transparent,
            child: Row(
              children: <Widget>[
                Expanded(
                  child: GestureDetector(
                    behavior: HitTestBehavior.translucent,
                    onTap: () {
                      print('user tapped first Inkwell');
                    },
                    child: Container(
                      decoration: BoxDecoration(
                          color: Colors.blueGrey,
                          image: DecorationImage(
                              image: CachedNetworkImageProvider(
                                  '${recipeList[index].image}'),
                              fit: BoxFit.cover),
                          borderRadius: BorderRadius.circular(20),
                          boxShadow: [
                            BoxShadow(
                              color: recipeList[index].type == 'nveg'
                                  ? Colors.red.withOpacity(0.9)
                                  : Colors.green.withOpacity(0.9),
                              spreadRadius: 3,
                              blurRadius: 10,
                            )
                          ]),
                      child: Text('hello how are you'),
                    ),
                  ),
                ),
                Expanded(
                    child: Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      boxShadow: kboxShadow,
                      borderRadius: BorderRadius.only(
                          topRight: Radius.circular(20),
                          bottomRight: Radius.circular(20))),
                  height: 120,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        recipeList[index].name,
                        textAlign: TextAlign.center,
                        style: kNepaliTextStyle.copyWith(
                            fontWeight: FontWeight.bold),
                      ),
                      Text('Veg'),
                    ],
                  ),
                ))
              ],
            ),
          ),
        );
      }),
    );
  }
}
类ListCard扩展StatefulWidget{
@凌驾
_ListCardState createState()=>\u ListCardState();
}
类_ListCardState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.white,
正文:专栏(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
填充物(
填充:仅限常量边集(左:10.0,右:10,顶:15),
子项:搜索栏(),
),
已展开(子项:RecipeListWheel()),
],
),
);
}
}
类RecipeListWheel扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回ListWheelScrollView.useDelegate(
直径比:1.2,
透视图:0.0001,
项目范围:150,
childDelegate:ListWheelChildBuilderDelegate(
生成器:(BuildContext上下文,int索引){
如果(索引<0 | |索引>10 | |索引>recipeList.length-1){
返回null;
}
返回填充(
填充:常量边集。对称(水平:15.0),
子:容器(
身高:240,
颜色:颜色。透明,
孩子:排(
儿童:[
扩大(
儿童:手势检测器(
行为:HitTestBehavior.transparent,
onTap:(){
打印(“用户点击第一个墨水池”);
},
子:容器(
装饰:盒子装饰(
颜色:颜色。蓝灰色,
图像:装饰图像(
图像:CachedNetworkImageProvider(
“${recipeList[index].image}”),
安装:BoxFit.盖),
边界半径:边界半径。圆形(20),
boxShadow:[
箱形阴影(
颜色:recipeList[索引]。类型=='nveg'
?颜色。红色。不透明度(0.9)
:颜色。绿色。不透明度(0.9),
扩展半径:3,
半径:10,
)
]),
孩子:文本(‘你好’),
),
),
),
扩大(
子:容器(
装饰:盒子装饰(
颜色:颜色,白色,
boxShadow:kboxShadow,
borderRadius:仅限borderRadius(
右上角:半径。圆形(20),
右下角:半径。圆形(20)),
身高:120,
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
正文(
recipeList[索引]。名称,
textAlign:textAlign.center,
样式:kNepaliTextStyle.copyWith(
fontWeight:fontWeight.bold),
),
文本('Veg'),
],
),
))
],
),
),
);
}),
);
}
}
尝试添加

手势识别器:[
新工厂(()=>新的GuardgestureRecognitor(),),
].toSet(),

添加到要将onTap分配到的小部件。

尝试添加

手势识别器:[
新工厂(()=>新的GuardgestureRecognitor(),),
].toSet(),

要将onTap分配到的小部件