【问题标题】:How to hide a Row widget within a Column widget in Flutter如何在 Flutter 的 Column 小部件中隐藏 Row 小部件
【发布时间】:2021-03-08 23:24:45
【问题描述】:

我有以下代码在警报中显示一列。行以分钟为单位显示中断值。如果变量(break1、break2 等)为 0,我不想显示该行。我该怎么做呢?谢谢。

content: Column(
  children: <Widget>[
    Row(
      children: <Widget>[
        Expanded(
          flex: 38,
          child: Text(
            'Break 1:',
            style: TextStyle(color: kBodyText, fontSize: 16),
          ),
        ),
        Expanded(
          flex: 62,
          child: Text(
            '$break1 minutes',
            style: TextStyle(color: kBodyText, fontSize: 16),
          ),
        ),
      ],
    ),
    Row(
      children: <Widget>[
        Expanded(
          flex: 38,
          child: Text(
            'Break 2:',
            style: TextStyle(color: kBodyText, fontSize: 16),
          ),
        ),
        Expanded(
          flex: 62,
          child: Text(
            '$break2 minutes',
            style: TextStyle(color: kBodyText, fontSize: 16),
          ),
        ),
      ],
    ),
  ],
),

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    将您的 Row 包装在 Visibility Widget 中,并根据要求将可见设置为 true 或 false。

     Visibility(
         visible:
             !state.getListApiCalled ? true : false,
                                  child: Padding(
                                      padding: EdgeInsets.all(
                                          ResponsiveFlutter.of(context).hp(6)),
                                      child: CircularProgressIndicator(
                                        strokeWidth: 5,
                                      )),
                                ),
    

    【讨论】:

    • getListApiCalled 是什么?
    • getListApiCalled 是我的状态类中使用的布尔值,您可以使用其他任何值。就像问题中所问的那样,如果 beark1 变量的值为 0 那么:可见:break1==0?false:true
    【解决方案2】:

    使用Visibility

    visible:false 用于隐藏特定的小部件。

    所以代码看起来像这样:

       Visibility(visible:false, child:Row());
    

    【讨论】:

      猜你喜欢
      • 2020-03-08
      • 2020-04-16
      • 1970-01-01
      • 2023-01-09
      • 2021-01-17
      • 2021-07-18
      • 2020-11-16
      • 2019-06-11
      • 1970-01-01
      相关资源
      最近更新 更多