首页 > 解决方案 > 当溢出为溢出时,IconButton 的 onPressed 不会在堆栈小部件内被调用。

问题描述

我有以下代码

void showShortBioDialog(BuildContext context) {
    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return Dialog(
            child: Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                Container(
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 10, 0, 40),
                    child: Text(
                      "Short Bio",
                      textAlign: TextAlign.center,
                      style: TextStyle(color: white, fontFamily: "BarlowBold"),
                    ),
                  ),
                  color: blue2,
                  width: double.infinity,
                ),
                Positioned(
                  top: 30,
                  right: -5,
                  left: -5,
                  child: Card(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(5),
                    ),
                    elevation: 0,
                    child: Container(
                      height: 180,
                      child: Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 10),
                        child: TextField(),
                      ),
                    ),
                  ),
                ),
                Positioned(
                  bottom: -170,
                  right: 0,
                  left: 0,
                  child: IconButton(
                    onPressed: () {
                      print("hi");
                    },
                    iconSize: 35,
                    icon: Image.asset(
                      "images/next_signup.webp",
                      fit: BoxFit.fill,
                      height: 35,
                      width: 35,
                    ),
                  ),
                )
              ],
            ),
          );
        });
  }

对话框看起来像我想要的那样正确,并且在屏幕出现时触发对话框。但iconbutton's onPressed从未调用过我尝试用 , 等替换图标按钮InkWellRaisedButtonFlatButton从未onPressed调用过该按钮。图标按钮的位置也在堆栈的最后,但我仍然很困惑为什么不调用它的点击。

我想要一个类似于以下的输出

https://drive.google.com/file/d/1K12-Dw4xRzHNd9N1gM02TcHd6TdK319Y/view?usp=sharing

标签: dartflutter

解决方案


我认为是因为溢出。如果您发表评论overflow: Overflow.visible,那么您将根本看不到图像。尝试使对话框足够大,以使图像位于顶部而不会溢出。


推荐阅读