Are there any difference in both of them?
Whats the disadvantage and which one is easier to use for normal situation?
Are there any difference in both of them?
Yes. They are different.
src
URL passed to it. It is not a widget and does not output an image to the screen.Image.network creates a widget that displays an image on the screen. It is just a named constructor on the Image class(a stateful widget). It sets the image
property using the NetworkImage
. This image
property is used finally to display the image.
class Image extends StatefulWidget{
Image(...){}; //default Constructor
//the argument src is passed to the NetworkImage and assinged to the image property
Image.network(String src, {...}) : image = NetworkImage(src, ...);
final ImageProvider image;
@override
Widget build(BuildContext context){
display the image
return RawImage(image: image,
...
);
}
}
Whats the disadvantage and which one is easier to use for normal situation?
There is no disadvantage. You should use the one the suits the need. For example consider:
backgroundImage
. It requires an ImageProvider. So you pass NetworkImage(http://image.com)
ImageProvider
for its image
property. So you can provide it NetworkImage(http://image.com)
.If you just want to display the image as a widget on screen use Image.network
and use NetworkImage
wherever an ImageProvider
is expected.