Flutter-GestureDetector 不适用于堆栈中的容器

标签 flutter gesturedetector

我有两个容器在一个堆栈中,两个容器都有 GestureDetector。第一个容器的 OnTap 工作正常,但它不适用于另一个容器。 第一个容器是图像,第二个容器是部分对齐在第一个容器上方的绿色背景。

new Stack(
            alignment: Alignment(0.0, 1.44),
            children: <Widget>[
              GestureDetector(
                onTap: () => _openImage(context),
                child: Container(
                  width: 340.0,
                  foregroundDecoration: new BoxDecoration(
                      color: Color.fromRGBO(155, 85, 250, 0.55)),
                  height: 240.0,
                  child: FadeInImage.assetNetwork(
                    placeholder: 'assets/dimlight.png',
                    image: post.imageUrl,
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              new GestureDetector(
                child: new Container(
                  color: Colors.green,
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    children: <Widget>[
                      SizedBox(width: 7.0),
                      CircleAvatar(
                        backgroundImage: 
                           new AssetImage("assets/boy.png")
                        radius: 30.0,
                      ),
                      SizedBox(
                        width: 7.0,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          new SizedBox(
                            height: 20.0,
                          ),
                          Text(
                            post.user.name,
                            style: TextStyle(fontWeight: FontWeight.bold),
                          ),
                          Text(
                            getTimeString(post.timestamp.toString()),
                            style: TextStyle(
                                color: Colors.grey, fontSize: 10.0),
                          ),
                        ],
                      ),
                      SizedBox(
                        width: 20.0,
                      ),
                    ],
                  ),
                ),
                onTap: () => _navigateToDetails(context),
              )
            ],
          )

布局截图

enter image description here

最佳答案

尝试将 GestureDetectorbehavior 属性设置为 HitTestBehavior.translucent

关于Flutter-GestureDetector 不适用于堆栈中的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52965799/

相关文章:

dart - flutter 中的侧面径向菜单

android - 单击通知按钮不会在 flutter 中打开应用程序

android - 在双击和滑动之间切换

android - 如何使用 onScroll 和 GestureDetector 使 View 跟随我的手指 - Android

android - longPress 不回复 ACTION_UP - 简单的手势监听器

android - 如何在 dart/flutter 中提取 JSON 子数据

堆叠的列和行中的 Flutter Textwrapping

flutter - 如何在 flutter Dart 中从两个字符串生成一个字符串/哈希

flutter - 如何用另一个 GestureDetector 包装 GestureDetector 并在任何地方获取事件