本文介绍了未收到堆栈边界之外的手势响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个可调整大小的小部件,该小部件的拐角处带有手柄。角落句柄将在 Stack 中溢出其宽度/高度的一半。

I am trying to implement a re-sizable widget with handles at the corners. The corner handles will be overflow the Stack by half of its width/height.

问题:手柄的外部不报告手势事件,而内部却可以正常工作。

Issue: the outer part of handle does not report gesture events while the inner part is working fine.

这是有意的,或者我做错了什么。如果是预期的行为,那么下一步该怎么做。

It is intended or I am doing some thing wrong. If it is intended behavior then what to do next.

示例代码

      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.green,
          body: Transform.translate(
            offset: boxOffset,
            child: Stack(
              overflow: Overflow.visible,
              fit: StackFit.expand,
              children: <Widget>[
                Container(
                  width: 100.0,
                  height: 100.0,
                  color: Colors.red,
                ),
                Positioned(
                  left: 100.0 - 20.0,
                  top: 100.0 - 20.0,
                  child: GestureDetector(
                    onTap: () {print("tapped");},
                    child: Container(
                      width: 80.0,
                      height: 80.0,
                      color: Colors.blue,
                    ),
                  ),
                )
              ],
            ),
          )
        );
    }

推荐答案

这是所需的行为。如果小部件可以捕获其边界之外的指针事件;很容易陷入无法确定目标是哪个小部件的情况。

This is the desired behavior. If widgets could catch pointer events outside of their boundaries; it would be easy to fall into a situation where it's impossible to determine which widget is targeted.

简而言之,不要使用溢出。重构您的布局,以确保其完全包含在其父级的边界内。

In short, don't use overflow. Refactor your layout to make sure it's well contained inside the bounds of its parent.

这篇关于未收到堆栈边界之外的手势响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:15