How to use conditional statement within child attribute of a Flutter Widget (Center Widget)

前端 未结 18 2158
再見小時候
再見小時候 2020-11-30 18:50

So far whenever I needed to use a conditional statement within a Widget I have done the following (Using Center and Containers as simplified dummy examples):



        
18条回答
  •  忘掉有多难
    2020-11-30 19:37

    For the record, Dart 2.3 added the ability to use if/else statements in Collection literals. This is now done the following way:

    return Column(children: [
      Text("hello"),
      if (condition)
         Text("should not render if false"),
      Text("world")
    ],);
    

    Flutter Issue #28181 - Inline conditional rendering in list

提交回复
热议问题