Issue
Is there any way you can control exceptions launched by Image.network() so you can provide it a default AssetImage ?
Solution
It depends on your use case, but one way to do it is to use FadeInImage
which has a property of img
for the image that is intended to load, and placeholder
, well, for the placeholder
FadeInImage(image: NetworkImage(url), placeholder: AssetImage(assetName)
You can also listen until the image is loaded and show a placeholder yourself until fetching the image resolves.
pseudo code
bool _loaded = false;
var img = Image.network(src);
var placeholder = AssetImage(assetName)
@override
void initState() {
super.initState();
img.image.resolve(ImageConfiguration()).addListener((i, b) {
if (mounted) {
setState(() => _loaded = true);
}
});
}
@override
Widget build(BuildContext context) {
return YourWidget(
child: _loaded ? img : placeholder,
);
}
Answered By - Shady Aziza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.