Pages

04 June, 2024

Why do I get an Invalid Argument Exception when displaying a network image?

Sometimes when I call this code:
Widget displayImage(BuildContext context, MyBook book) {
if (book.coverUrl != null) {
try {
return Image.network(book.coverUrl!,
errorBuilder: (context, error, stackTrace) {
return Text('No \nimage');
});
} on Exception {
return Text('No \nImage');
}
} else {
return Text('No \nImage');
}
}



I receive the message



════════ Exception caught by image resource service ══════════════════


Invalid argument(s): No host specified in
URI file:///home/alan/FlutterProjects/books/null
═══════════════════════════════════════════════════════



(file:///home/alan/FlutterProjects/books/ is my app's path. book.coverUrl is a String.)
The online image displays properly, despite the Exception message.


What causes this? Do I need to fix it?


EDIT:
The end of the stack track also includes the message:



Image provider: NetworkImage("null", scale: 1.0)




Image key: NetworkImage("null", scale: 1.0)

No comments:

Post a Comment

Thanks