When I use to call an image by API it shows it need a null Checker
DownloadsImageWidget(
imageList:
'$imageAppendUrl${state.downloads?[1].posterPath}',
margin: const EdgeInsets.only(),
size: Size(
size.width * 0.4,
size.height * 0.30,
),
),
I tried to put a null checker ? , then I will never get a image because of wrong URL.
its shows this error HTTP request failed, statusCode: 404, https://image.tmdb.org/t/p/w500null
when I tried to give ! Null check operator used on a null value
I get this error.
2
Answers
I guess you can try to add a ternary operator to check whether your
state.downloads
is not null:I assume that the posterPath is the non-null attribute.
Then you can check if the
downloads
is empty or not before passing its list item.Example: