Flutter - Ontap InkWell 在 Stack 中不起作用

标签 flutter

我从flutter开始,使用onTap()有问题。

我使用 adobeXd 来制作我的模板,但我似乎无法放置 GestureDetector 和 InkWell 小部件。

Transform.translate(
        offset: Offset(MediaQuery.of(context).size.width / 30, 132.0),
        child:
        Stack(
          children: <Widget>[
            Transform.translate(
              offset: Offset(MediaQuery.of(context).size.width / 1.7, 1.0),
              child:
              InkWell(
                onTap: (){
                  setState(() {
                    actu = true;
                  });
                  print('ink');

                },
                child: Stack(
                  children: <Widget>[
                    Container(
                      width: MediaQuery.of(context).size.width / 2.85,
                      height: 36.0,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(19.0),
                        color: const Color(0x35ffffff),
                      ),
                    ),
                    Transform.translate(
                      offset: Offset(MediaQuery.of(context).size.width / 3.7, 6.0),
                      child:
                      // Adobe XD layer: 'Icones/actualiser' (component)
                      XDIconesactualiser(),
                    ),
                    Transform.translate(
                      offset: Offset(MediaQuery.of(context).size.width / 21.47, MediaQuery.of(context).size.height / 110),
                      child:
                      SizedBox(
                        width: 75.0,
                        height: 27.0,
                        child: Text(
                          'Actualiser',
                          style: TextStyle(
                            fontFamily: 'OpenSans-SemiBold',
                            fontSize: 14,
                            color: const Color(0xffffffff),
                          ),
                          textAlign: TextAlign.left,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),

onTap 不起作用。似乎是当它在 Stack 或 Transform 中时。 你能帮帮我吗?

编辑:

事件未触发。没有任何事情发生,就好像它不存在一样。当我在开发工具中查看树时,出现了墨水瓶,但是当我点击手机时没有任何反应

The image of my Flutter tree

编辑 2:

我想要这样的结构

Expected

但是当我停用偏移量以使点击起作用时。我明白了

Reality

最佳答案

我遇到了同样的问题。将 Inkwell 的 child 包裹在 IgnorePointer 中解决了这个问题。

在这里解决:Flutter - InkWell not reacting to onTap inside Flexible

关于Flutter - Ontap InkWell 在 Stack 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62861735/

相关文章:

android - Flutter:如何使用 "Multi Image Picker"降低图像质量并获得输出为 "File"?

dart - 如何在文本中有一个小部件?

listview - FutureBuilder 只加载一次 API 数据

firebase - 为了使用 Firebase Cloud Messaging,我必须将哪些 API 限制列入白名单?

flutter - 如何使用 flutter 为 ios 创建下拉菜单?

dart - 如何使 TextFormField 文本在验证时显示在 TextFormField 行下方

flutter - Android 依赖项 'com.google.android.gms:play-services-tasks' 具有不同版本的编译 (16.0.1) 和运行时 (17.0.0) 类路径

rest - 当 API 调用的响应 statusCode 大于 400 时在 Flutter 中构建小部件

flutter - 如何解决错误 : The sandbox is not in sync with the Podfile. 锁

Flutter:升级android compiledSdkVersion