gpt4 book ai didi

flutter - 在 Positioned 小部件问题中使用 RaisedButton 小部件

转载 作者:IT王子 更新时间:2023-10-29 06:39:12 25 4
gpt4 key购买 nike

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

问题出在我使用 RaisedButton 时里面Positioned小部件,onPressed单击 RaisedButton 时未触发事件 child ,但是当我点击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,
)

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

最佳答案

简短的回答是:

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

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

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

关于flutter - 在 Positioned 小部件问题中使用 RaisedButton 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com