1

Sometimes we need to run app by clearing app data and cache. It is a hassle to do it manually every time going to setting screens.I saw maximum stack-overflow answers recommending it programmatically but I don't need it. Is there any flutter command or plugin to do that?

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42

1 Answers1

1

There is actually no flutter command to clear app data.

However, you could use prelaunch tasks to run shell command before launching your app.

You must have adb command in your environment PATH variable for Android apps

For example, in VsCode, you can add a task in the tasks.json file like this :

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "clear app data",
            "type": "shell",
            "command": "adb shell pm clear com.package.app || true;xcrun simctl uninstall booted com.package.app",
            "problemMatcher": []
        }
    ]
}

Then, add the preLaunchTask in your launch.json file like this :

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "my_app",
      "request": "launch",
      "type": "dart",
      "program": "lib/main.dart",
      "preLaunchTask": "clear app data",
    }
  ]
}

I don't know how to do this in IntelliJ but I'm sure you can do the same thing

F Perroch
  • 1,988
  • 2
  • 11
  • 23