代码之家  ›  专栏  ›  技术社区  ›  RISKAY

当我试图使用API时,出现了参数类型“String?”无法分配给参数类型“String”[重复]

  •  -3
  • RISKAY  · 技术社区  · 3 年前

    the imageUrl this is the api from json

    当我试图使用API时,出现了参数类型“String?”无法分配给参数类型“String”

    2 回复  |  直到 3 年前
        1
  •  0
  •   Orkun Uguz    3 年前

    我认为它给出了这样一个错误,因为颤振具有零安全特性。尝试 Image.asset(space.imageUrl!) 或者只为变量指定一个默认值。前任: Image.asset(space.imageUrl ?? "imageUrl failed to load")

        2
  •  0
  •   mario francois    3 年前

    试试这个:

    if (space.imageUrl != null) Image.asset(space.imageUrl!),
    

    Image.asset(space.imageUrl ?? "assets/img/img_not_available.jpeg"),