NetworkImage cannot be assigned to type Widget

Question

Asked by ameiyil on November 07, 2017 (source).

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'.

Answer

Question answered by ameiyil (source).

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')
  ]
)
FLUTTER
SHARE: