Flutter: how do I delete FlutterSecureStorage items during install/uninstall

On iOS you can make use of NSUserDefaults, which does get deleted on an app uninstall. That way you can perform a check whether the app is starting for the first time after an uninstall. Use the shared_preferences Flutter plugin to make use of NSUserDefaults.

This approach has been discussed on StackOverflow for other platforms before, see Delete keychain items when an app is uninstalled for examples in other languages.

For Flutter this example would become:

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

// ...

final prefs = await SharedPreferences.getInstance();

if (prefs.getBool('first_run') ?? true) {
  FlutterSecureStorage storage = FlutterSecureStorage();

  await storage.deleteAll();

  prefs.setBool('first_run', false);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)