-3

the imageUrlthis is the api from json

when i trying to use API this appeared The argument type 'String?' can't be assigned to the parameter type 'String'

RISKAY
  • 25
  • 3
  • Please paste the code as text in the question body using the Code Sample option {}. – Wilson Toribio Apr 06 '22 at 13:22
  • a quick fix would be to add `!` behing it, like `space.imageUrl!` but I suggest you to read https://dart.dev/null-safety/understanding-null-safety to understand what it means – Ivo Apr 06 '22 at 13:27

2 Answers2

1

I think it gives such an error because flutter has a null safety feature. Try Image.asset(space.imageUrl!) or just assign a default value for your variable. Ex: Image.asset(space.imageUrl ?? "imageUrl failed to load")

Orkun Uguz
  • 88
  • 7
0

Try this:

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

or

Image.asset(space.imageUrl ?? "assets/img/img_not_available.jpeg"),
mario francois
  • 1,291
  • 1
  • 9
  • 16