【问题标题】:Ternary operator showing checked exception with imageProvider使用 imageProvider 显示已检查异常的三元运算符
【发布时间】:2022-01-08 02:31:36
【问题描述】:

当我使用相同类型的 imageProvider 时没有显示异常,但使用三元运算符时显示异常。

CircleAvatar(
                  backgroundImage: imageFile != null
                      ? FileImage(File(imageFile!.path))
                      : AssetImage("assets/images/camera.png")),
            ),

【问题讨论】:

  • 请不要在没有以文本形式提供代码的情况下添加代码截图。此外,最好包含嵌入问题中的图像,而不是链接。
  • 对不起,我不知道如何正确使用它......下次一定会关心它
  • 两个是不同的返回类型,这就是显示错误的原因。这实际上不是三元运算符的问题。
  • 我该如何解决?

标签: android flutter dart


【解决方案1】:

试试这样:

  imageFile != null ?
 CircleAvatar(
  backgroundImage:  FileImage(File(imageFile!.path))) :  
 CircleAvatar(
    backgroundImage: AssetImage("assets/images/camera.png")),
        

【讨论】:

    猜你喜欢
    • 2019-09-20
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 2015-07-31
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    相关资源
    最近更新 更多