ensureInitialized static method

Future<void> ensureInitialized({
  1. String? subDir,
})

ensureInitialized initialized the ThemeStorageService

The subDir will now be deleting the directory of the theme storage, if it exists.

Implementation

static Future<void> ensureInitialized({
  String? subDir,
}) async {
  if (subDir != null) {
    if (kIsWeb) return;

    final Directory appDir = await getApplicationDocumentsDirectory();
    final String pathToDelete = path_helper.join(appDir.path, subDir);
    final Directory dir = Directory(pathToDelete);
    if (await dir.exists()) {
      await dir.delete(recursive: true);
    }
  }

  final SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
  _themeStorageService = ThemeStorageService(sharedPreferences: sharedPrefs);
  _themeStorageService.addListener(() {
    _instance.notifyListeners();
  });
}