How does app cache work in FlutterFlow and how can I clear it inside the app?

Troubleshooting
Resolved

I’m facing an issue with cache accumulation in my FlutterFlow app.

Here’s the context:

  • I only use Firebase for photo uploads.

  • For my main database, I integrate with Bubble via a custom API (not Firebase Firestore/RTDB).

  • When users upload photos, I first convert them to base64 using Upload/Save Media, then I call my API.

  • After sending the data, I use “Clear Uploaded Data” to release the temporary images.

Even with this workflow, the app seems to accumulate cache over time.

My questions are:

  1. How does FlutterFlow handle cache storage under the hood (for images, API data, etc.)?

  2. Is there a way to programmatically clear the app cache from inside the app (via custom action or Dart code), instead of asking users to manually go to device settings → Clear Cache?

My goal is to give users a button or an in-app action that behaves the same as the Clear Cache option in Android/iOS app settings.

Has anyone run into this and found a solution or workaround?

What have you tried so far?

I tried using this Custom Action:

```

Future<String> clearAppCaches(
  bool clearSharedPrefs,
  bool clearSupportDirs,
) async {
  int deletedFiles = 0;
  int deletedDirs = 0;

  Future<void> _deleteDirContents(Directory dir) async {
    if (!await dir.exists()) return;
    await for (final entity in dir.list(followLinks: false)) {
      try {
        if (entity is File) {
          await entity.delete();
          deletedFiles++;
        } else if (entity is Directory) {
          await entity.delete(recursive: true);
          deletedDirs++;
        }
      } catch (e) {
        debugPrint('Falha ao deletar ${entity.path}: $e');
      }
    }
  }

  try {
    try {
      PaintingBinding.instance.imageCache.clear();
      PaintingBinding.instance.imageCache.clearLiveImages();
    } catch (_) {}

    try {
      await DefaultCacheManager().emptyCache();
    } catch (_) {}

    try {
      final tmpDir = await getTemporaryDirectory();
      await _deleteDirContents(tmpDir);
    } catch (e) {
      debugPrint('Erro ao limpar getTemporaryDirectory: $e');
    }

    return 'Cache limpo. Arquivos apagados: $deletedFiles, pastas: $deletedDirs'
        '${clearSharedPrefs ? ' (Prefs limpas)' : ''}'
        '${clearSupportDirs ? ' (Support/Docs limpos)' : ''}.';
  } catch (e, s) {
    debugPrint('clearAppCaches error: $e\n$s');
    return 'clearAppCaches error: $e\n$s';
  }
}

```

Did you check FlutterFlow's Documentation for this topic?
No
2
6 replies