Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Delete cache and app dir in flutter

Tags:

flutter

dart

In my flutter app, I store some images in cache directory and some files in application document directory, now I want to add possibility to my users to delete the cache dir and app dir, How can I achieve this?

like image 938
mohammad Avatar asked Dec 08 '19 06:12

mohammad


People also ask

How do I delete cache folder in flutter?

Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.

Can I delete flutter bin cache folder?

You can run rm -rf ~/flutter/bin/cache in the terminal to clear the Flutter bin cache.

How do you clear data on flutter?

Step 1: Create a new project and launch main. dart file. Clear the existing code. import 'package:flutter/material.


1 Answers

You need path_provider package

Then try this code:

  Future<void> _deleteCacheDir() async {
    final cacheDir = await getTemporaryDirectory();

    if (cacheDir.existsSync()) {
      cacheDir.deleteSync(recursive: true);
    }
  }

  Future<void> _deleteAppDir() async {
    final appDir = await getApplicationSupportDirectory();

    if(appDir.existsSync()){
      appDir.deleteSync(recursive: true);
    }
  }
like image 143
Ramin Avatar answered Oct 01 '22 19:10

Ramin