【问题标题】:How to write if condition in widget flutter [duplicate]如何在小部件颤动中编写if条件[重复]
【发布时间】:2020-05-30 07:57:02
【问题描述】:

在此之前,我的代码没有错误。在我将颤振升级到最新版本之后。然后我在 if 条件下得到错误

Column(
             children: <Widget>[
               if(imageFile != null) ...[
                 Center(
                     .....
                ),
               ]
             ],
            ),

这是我的错误:

This requires the 'spread-collections' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running. 

有人知道如何解决这个错误吗?

【问题讨论】:

  • 您是否将图像显示为 Center() 列表?

标签: flutter


【解决方案1】:

这是一个分析器问题 要解决在项目的根目录中创建一个名为 analysis_options.yaml 的文件,然后在文件中放这个

analyzer:
  enable-experiment:
    - spread-collections

【讨论】:

    【解决方案2】:

    你可以试试ternary if 语句

    Column(
        children: <Widget>[
            (imageFile != null)?
            Center(...) : 
            Text("Image Not Found"),
        ]
    ),
    

    【讨论】:

      猜你喜欢
      • 2020-04-11
      • 2011-12-23
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 2014-02-20
      • 1970-01-01
      相关资源
      最近更新 更多