Image cannot be null using FadeInImage and url [Flutter]
195
imageErrorBuilder will only be called if there is an error occurs during image loading, example the image path does not exist.
To fix your issue, you have to check whether url is null or empty. If it is null, display another widget, else display FadeInImage
.
newsList[index].urlToImage == null ? DisplayNoImage: FadeInImage.assetNetwork(...),
Comments
-
Don over 1 year
Hello so I added a way to display my url images in a list but because Im fetching this information from public API some of them are missing URLs and errors occur, I tried using placeholder and image errorbuilder but that didnt help
Here is my code:
child: FadeInImage.assetNetwork( height: 100, width: 100, fit: BoxFit.fill, image: newsList[index].urlToImage, placeholder: 'images/placeholder.png', imageErrorBuilder: (context, error, StackTrace) { return const Image( height: 100, width: 100, image: AssetImage("images/placeholder.png")); }, ),
and Error:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building: 'package:flutter/src/widgets/fade_in_image.dart': Failed assertion: line 234 pos 15: 'image != null': is not true.
Updated Code:
child: newsList[index].urlToImage == null ? Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage("images/placeholder.png"), ), ), ) : FadeInImage.assetNetwork( height: 100, width: 100, fit: BoxFit.fill, image: newsList[index].urlToImage, placeholder: 'images/placeholder.png', imageErrorBuilder: (context, error, StackTrace) { return const Image( height: 100, width: 100, image: AssetImage("images/placeholder.png")); }, ),
-
Don about 2 yearsFirst of all thank you for quick reply I followed your instructions and this is what my code is now along with the error (updated question)
-
John Joe about 2 yearsquestion not updated.
-
Don about 2 yearsCheck again I updated it few second ago
-
John Joe about 2 years"A non-null String must be provided to a Text widget" The latest error shows the
String
in theText
widget is null. Did the error point to which line? -
Don about 2 yearsWhen I check the text.dart the line 378 its this : assert( data != null, 'A non-null String must be provided to a Text widget.', ),
-
John Joe about 2 yearsPost the full exception.
-
Don about 2 yearsI edited question with full exception
-
John Joe about 2 yearsLet us continue this discussion in chat.