首页 > 解决方案 > Flutter:如何在 Flutter 的构建函数中添加“if”逻辑

问题描述

我在构建函数中有以下内容,我只希望它显示逻辑是否正确

if (!isKeyBoardVisible) 
     SizedBox(height: 13.0),
     buildApplyButton(),
     SizedBox(height: 20.0,)

但是,上述语句仅适用于第一个尺寸框。

我怎样才能使它完整的3个语句

谢谢

标签: flutter

解决方案


 isKeyBoardVisible
                  ? Column(
                      children: <Widget>[
                        SizedBox(height: 13.0),
                        buildApplyButton(),
                        SizedBox(
                          height: 20.0,
                        )
                      ],
                    )
                  : Column(
                      children: <Widget>[
                        SizedBox(height: 13.0),
                        buildApplyButton(),
                        SizedBox(
                          height: 20.0,
                        )
                      ],
                    )

: else 是三元运算符的一部分,你可以把你的 else 部分放在那里


推荐阅读