Reputation: 21
I'm just starting to learn Flutter and when trying to add an image with a network image as the source, I encountered this error. I tried to search solution for this but still can't find it. So anyone could enlighten me on what the problem could be ?. Thank you.
Here is the source code
Error: The argument type 'Image' can't be assigned to the parameter type 'ImageProvider<Object>'.
Upvotes: 2
Views: 1581
Reputation:
This error mainly cause just because you are providing "Image" rather then "ImageProvider".
code:
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: NetworkImage(
"https://picsum.photos/250?image=9"),
),
),
)
Upvotes: 0
Reputation: 572
While NetworkImage is a image provider, Image or Image.network are Widgets so you need to use Image.network() or Image class
Upvotes: 0
Reputation: 17880
There are two way to show network image in flutter.
First use NetworkImage
Image(
image: NetworkImage('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/chihuahua-dog-running-across-grass-royalty-free-image-1580743445.jpg?crop=0.446xw:1.00xh;0.254xw,0&resize=480:*'),
)
or use:
Image.network('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/chihuahua-dog-running-across-grass-royalty-free-image-1580743445.jpg?crop=0.446xw:1.00xh;0.254xw,0&resize=480:*')
Upvotes: 4