简体   繁体   English

忽略对 svg 图像 flutter 透明部分的 onTap 操作

[英]Ignore onTap action on Transparent part of the svg image flutter

Issue is that their are multiple svg images in stack.问题是它们是堆栈中的多个 svg 图像。 I need them to trigger only when the user tapped on filled part of the svg.我需要它们仅在用户点击 svg 的填充部分时触发。 So that, when it ignores on transparent part of the image, it can able to trigger behind svg image.这样,当它忽略图像的透明部分时,它可以在 svg 图像后面触发。

        Stack(
          children: [
            GestureDetector(
              onTap: () => updateSelectedPart(1),
              child: SvgPicture.asset(
                'assets/images/1.svg',
                color: selectedPart == 1
                    ? Colors.red
                    : Colors.blue,
              ),
            ),
            GestureDetector(
              onTap: () => updateSelectedPart(2),
              behavior: HitTestBehavior.translucent,
              child: SvgPicture.asset(
                'assets/images/2.svg',
                color: selectedPart == 2
                    ? Colors.red
                    : Colors.blue,
              ),
            ),
            GestureDetector(
              onTap: () => updateSelectedPart(3),
              behavior: HitTestBehavior.deferToChild,
              child: AbsorbPointer(
                absorbing: true,
                child: SvgPicture.asset(
                  'assets/images/3.svg',
                  excludeFromSemantics: true,
                  clipBehavior: Clip.none,
                  color: selectedPart == 3
                      ? Colors.red
                    : Colors.blue,
                ),
              ),
            ),
          ],
        )

Ordering is bottom to top so you will need to adjust (change order in the stack) so that what might overlay another SVGs transparent part gets triggered on an action (click/touch event) not the SVG below it (Above it in this case as its bottom to top)排序是从下到上的,因此您需要调整(更改堆栈中的顺序),以便在操作(单击/触摸事件)而不是其下方的 SVG 时触发可能覆盖另一个 SVG 透明部分的内容(在这种情况下为上方)从下到上)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM