Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show image from network in flutter BoxDecoration?

Tags:

image

flutter

I want to show an image of the network in BoxDecoration. But its showing error

"The argument type 'image' can't be assigned to the parameter type 'imageProvider'".

Here is the code where I am trying to show an image from the network inside box decoration. Please check and do let me know where I am wrong in this code.

decoration: new BoxDecoration(     image: new DecorationImage(image: new Image.network("http://myurl.com/"+productList[index].thumbnail),     fit: BoxFit.cover) ), 
like image 337
Ammy Kang Avatar asked Jun 06 '18 06:06

Ammy Kang


People also ask

How do I use network image in decoration image in Flutter?

To load an image from network using NetworkImage , pass the image URL as the argument of NetworkImage . Then, pass the NetworkImage as the image argument of DecorationImage . Below is the URL of the image used in this tutorial.

How do I convert a network image into a file in Flutter?

File f = File("https://example.com/xyz.jpg"); The whole point is to get the image from the given URL and save it as a File variable.


2 Answers

I've resolved the issue, it can be achieved using this code.

decoration: BoxDecoration(       image: DecorationImage(image: NetworkImage("urlImage"),       fit: BoxFit.cover)     ), 
like image 58
Ammy Kang Avatar answered Sep 21 '22 11:09

Ammy Kang


if you want to load CachedNetworkImage then use in this way *** https://pub.dev/packages/cached_network_image

CachedNetworkImage(   imageUrl: "http://via.placeholder.com/200x150",   imageBuilder: (context, imageProvider) => Container(     decoration: BoxDecoration(       image: DecorationImage(           image: imageProvider,           fit: BoxFit.cover,           colorFilter:               ColorFilter.mode(Colors.red, BlendMode.colorBurn)),     ),   ),   placeholder: (context, url) => CircularProgressIndicator(),   errorWidget: (context, url, error) => Icon(Icons.error), ), 
like image 33
Muhammad Kashif Avatar answered Sep 17 '22 11:09

Muhammad Kashif