Baseflow / Baseflow/flutter_cache_manager

Error when used with cached_network_image by setting up the cacheManager

Ouverte
#410 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Dart
Étoiles
809
Forks
510
Merge moyen
6 min
PR mergées (30 j)
1

Description

## 🐛 Bug Report

I am experiencing an issue while using the `flutter_cache_manager` package along with the `cached_network_image` package in my Flutter project. I have set the `cacheManager` property and set the stalePeriod to 2 hours for my cache configuration. When I run my project in development mode after 1 or 2 days, an error occurs which stops the app process. The error message will be in screenshots. But the ending is: "OS Error: No such file or directory, errno = 2".

It seems like the app is trying to delete a non-existing cache file.

### Expected behavior
The app should run without any issues, and the cache should be managed appropriately.

### Actual behavior
The app "crashes" (in development mode) with the error message "OS Error: No such file or directory, errno = 2".

### Reproduction steps
1. Set up a project using the `cached_network_image` and `flutter_cache_manager` packages.
2. Configure the `stalePeriod` to be short (my case was 2 hours).
3. Run the project in development mode.
4. Close the app.
5. Wait for more than the `statePeriod`. In my case around 1 or 2 days.
6. Run the project again in development mode.

### Configuration
Flutter version: It was `3.5.x` or `3.6.x`. Now I use `3.7.11`
`cached_network_image` package version: `3.2.3`
`flutter_cache_manager `package version: `3.3.0`
Device/Emulator: Android emulator on Windows & iOS emulator on Mac
OS: Windows 11 & MacOS

### Additional Context
Here is the code snippet where I configure the cache manager and use the CachedNetworkImage widget:

```
Widget _buildPhoto(bool useDarkMode) {
return CachedNetworkImage(
imageUrl: photoUrl,
height: height,
alignment: const Alignment(-1.0, -1.0),
cacheManager: CacheManager(
Config(
'photoCache',
stalePeriod: const Duration(hours: 2),
),
),
fadeInDuration: Duration.zero,
fadeOutDuration: Duration.zero,
placeholder: (context, url) => Container(
color: useDarkMode ? DarkColors.lightColor : LightColors.lightColor,
),
errorWidget: (
BuildContext context,
String url,
dynamic error,
) {
return Container(
width: double.infinity,
height: height,
color: useDarkMode ? DarkColors.lightColor : LightColors.lightColor,
);
},
);
}
}
```

**Platform:**
- [x] :iphone: iOS

![image](https://user-images.githubusercontent.com/22119831/233999619-b51c9fb1-6469-4c2d-a062-2cd918157a19.png)
![image](https://user-images.githubusercontent.com/22119831/233999698-81e57248-f9b7-4f21-8194-ce3228c0f246.png)
![image](https://user-images.githubusercontent.com/22119831/233999746-f119770b-b0f5-41a9-979c-943f502afa53.png)

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Reproduire le problème avec cached_network_image 3.2.3 et flutter_cache_manager 3.3.0 en utilisant un CacheManager configuré avec un stalePeriod de deux heures, puis capturer l’erreur complète et la stack trace. Suivre l’opération de nettoyage du cache qui signale « No such file or directory » sur Android et iOS ; c’est terminé lorsque le scénario reproduit s’achève sans erreur non gérée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
dart, flutter
Domaine
mobile-dev
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.