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

标签 flutter dart

我遇到了 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/

相关文章:

Flutter ListTile 启用多选 onLongPress

flutter - 如何在 flutter/Dart block 中取消 'await for'

dart - FlutterLogo 可以拉伸(stretch)填充吗?

flutter - 将 DropdownButton 的选定值居中

flutter - 从主页退出,跳过登录页面

android - Flutter无法混淆和去除符号

sqlite - flutter SQflite : How to solve unhandled exception?

animation - 如何在Flutter中动态缩放小部件(在我的情况下为卡片)?

flutter - 我如何在 flutter 中进行第二排序

ios - 如何在 Xcode 中导入 Firebase