Baseflow / Baseflow/flutter_cached_network_image

How should I handle the fact that it's possible that my users don't have internet access?

Open
#393 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 💬 Questions and Help
So, my users might not have access to the internet but still request something. The BaseCacheManager will return the cached file (for which the validity has run out), and while trying to download the updated version it will throw a SocketException:
`SocketException: Failed host lookup: 'url here' (OS Error: No address associated with hostname, errno = 7)`.
I tried to catch this error, but for some reason it didn't get caught. I thought it was because the getSingleFile function will execute the unawaited(downloadFile(url)) and return the (old) cached file. That way the old cached file will pass through the try/catch block no problem, but the unawaited function will give an exception. I tried changing this by making my getSingleFile like this:
```Dart
@override
Future getSingleFile(String url, {Map headers}) async {
FileInfo cacheFile = await getFileFromCache(url);
if (cacheFile != null) {
if (cacheFile.validTill.isBefore(DateTime.now())) {
cacheFile = await downloadFile(url, authHeaders: headers);
}
return cacheFile.file;
}
return (await downloadFile(url, authHeaders: headers)).file;
}
```
This fixed it, but I'd like to have the functionality of still getting the outdated cached file even when downloading the new one failed, while letting the user know that they are looking at an outdated file, which is not possible doing it like this.
Does anyone have an idea how I can still catch the SocketException when using unawaited?

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.