I’m working on a Flutter app that retrieves anime data from the Jikan API (https://api.jikan.moe/v4/anime). I’m using CachedNetworkImage to display the anime images, but I’m encountering an error:
Error Message:
Invalid argument(s): No host specified in URI null
Here’s the relevant code snippet:
ListView.builder(
// ... other builder arguments
itemBuilder: (context, index) {
return AnimeDataItme(
imageUrl: animeData.data![index].images!.jpg!.imageUrl.toString(),
);
},
),
// Assuming AnimeDataItme builds the CachedNetworkImage
return CachedNetworkImage(
imageUrl: imageUrl,
fit: BoxFit.fill,
);
//web services
@RestApi(baseUrl: ApiConstants.apiUrl)
abstract class WebServices {
factory WebServices(Dio dio, {String baseUrl}) = _WebServices;
@GET(ApiConstants.apiUrl)
Future<Anime> getAnimeData();
}
//repo
Future<Anime> getAnimeData() async {
try {
final response = await _webServices.getAnimeData();
return response;
} on DioError catch (error) {
print("Error: ${error.message}");
throw Exception("Failed to get data information");
}
}
I’ve tried the following:
- Added http:// before the image URL.
- Ensured null safety throughout the code using the null-conditional operator (?.).
However, the error persists and changes to “http://null” with the first attempt.
I’d appreciate any help from the community in identifying the root cause of the null URL and suggesting solutions to fix this error. Has anyone encountered a similar issue or have any insights into what might be causing the problem?
Bobo Cacy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.