在 Positioned widget 中使用 RaisingButton widget 问题

Mah*_*loo 6 dart flutter

RaisedButton我在小部件中使用它时遇到了问题Positioned

问题是当我RaisedButton在内部 Positioned小部件中使用时,onPressed单击子项时事件没有触发RaisedButton,但是当我单击RaisedButton它的另一个空间时,事件就起作用了。

RaisedButton请注意,它在正常情况下工作正常,并且在使用内部小部件时发生Positioned

这是我的小部件:

Positioned(
    child: Center(
        child: SizedBox(
            width: 80,
            height: 65,
            child: RaisedButton(
                padding: EdgeInsets.all(0),
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                color: Colors.green,
                child: Icon(Icons.message, size: 50, color: Colors.white,), 
                // When I clicked on this icon, onPressed didn't triggered. but when I click on another space of button it triggered.
                onPressed: () {
                    print('Hello world from onPressed');
                },
            ),
        ),
    ),
    top: -30,
    left: 0,
    right: 0,
)
Run Code Online (Sandbox Code Playgroud)

你有什么想法来解决这个问题?

The*_*nut 4

简短的回答是:

Flutter 不会触发与堆栈边界重叠的项目的推送事件(这就是将 top 设置为 -30 时所做的事情)。

这背后的原因可以在这里找到:Document that widgets in the Overflow of stack do not respond togesture

一个可能的解决方案是将所有其他项目移动 30.0 以下,这样您就可以将按钮放置在堆栈中。