How to conditionally add widgets to a list?

后端 未结 3 2016
醉酒成梦
醉酒成梦 2020-12-30 00:01

In flutter, widgets such as Row/ListView/Stack don\'t handle null children. So if we want to conditionally add widgets as children I u

3条回答
  •  春和景丽
    2020-12-30 00:37

    Here's a simpler version I use:

    Row(
      children: [
        Text("always included"),
        skipNulls([
          icon,
          label,
        ]),
      ],
    );
    
    skipNulls(List items) {
      return items..removeWhere((item) => item == null);
    }
    

提交回复
热议问题