1

When using a network image in flutter sometimes I got the error Connection closed before full header was received. The code below allows me to output the error but how can I force the widget to reload the image?

Image.network(p.thumbURL,
  errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {
    Log.e(exception);
    return Container();
  },
),
J. S.
  • 8,905
  • 2
  • 34
  • 44
MarcS82
  • 2,065
  • 7
  • 29
  • 46

1 Answers1

1
  1. give a value key to your image widget, otherwise it won't rebuild when you update your link
key: ValueKey(url),
  1. update your url by adding a new meaningless query string at the end, e.g. adding a time
setState(() { 
    url = url.split('?r')[0] + '?r=' + DateTime.now().millisecondsSinceEpoch.toString();
});
ltk
  • 994
  • 7
  • 9