3

I launch the app without network. Then I make network available and click setState button, the image is still not visible. Is there a solution?

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Column(
          children: <Widget>[
            Container(
              color: Colors.blue,
              child: Image.network(
                  'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3500755592,262843410&fm=26&gp=0.jpg'),
              width: 100,
              height: 100,
            ),
            RaisedButton(
              child: Text('setState'),
              onPressed: () {
                setState(() {});
              },
            ),
          ],
        ));
  }
Pete Houston
  • 14,931
  • 6
  • 47
  • 60
Jack Ma
  • 31
  • 4
  • https://github.com/flutter/flutter/pull/25980 – CopsOnRoad Jan 18 '19 at 09:16
  • I find that when an image loads failed, the url of this image will be recognized unavailable. Null will be returned when request the same image again. Is there any way to fix it? – Jack Ma Jan 18 '19 at 09:16

1 Answers1

0

There's nothing to change in your Image.network(..) so it's not going to respond to setState(), your url and sizes are all constant.

Give it something to change, like a key. Also, since it already has stored a failed image in its cache, you probably need to refresh the cache too. Here's a simple sample:

Image.network(
  "https://picsum.photos/250?image=9",
  key: ValueKey(_key)
)

setState(() {
  imageCache.clear();
  _key = DateTime.now().millisecondsSinceEpoch.toString();
});
TWL
  • 6,228
  • 29
  • 65