I tried to create add an image to my ListView by doing the following
new ListView(
children: <Widget>[
new NetworkImage('my_image_url')
]
)
and got the following error:
The element type 'NetworkImage' can't be assigned to the list type 'Widget'.
NetworkImage isn't a Widget, instead it:
Fetches the given URL from the network, associating it with the given scale.
Thus, it's used in Widgets like CircleAvatar to provide the source for its image.
The correct way to add an image via a url is to use Image.network('url'):
new ListView(
children: <Widget>[
new Image.network('my_image_url')
]
)
NetworkImage
doesn't just:
Fetches the given URL from the network, associating it with the given scale.
It can be used to display an image. In fact you will need it for something called DecoratedBox
, which IS a Widget.
Compared to the simple Image.network('my_url')
, using DecoratedBox
has a few advantages. Because you can alter that image.
You have access to filters, slice, shadows, or even borders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With