feat: preference helper singleton for easy access for preferences

This commit is contained in:
Yashas H Majmudar
2025-03-23 14:25:06 -04:00
parent 49e8e53126
commit 5c0eba2ed1

View File

@@ -0,0 +1,26 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shared_preferences/util/legacy_to_async_migration_util.dart';
class PreferenceHelper {
SharedPreferencesAsync _asyncPref = SharedPreferencesAsync();
PreferenceHelper._instantiate();
static final PreferenceHelper _instance = PreferenceHelper._instantiate();
static SharedPreferencesAsync get asyncPref => _instance._asyncPref;
static PreferenceHelper get instance => _instance;
Future<void> migrationSupportFunctionForSharedPreferences() async {
const SharedPreferencesOptions sharedPreferencesOptions =
SharedPreferencesOptions();
final SharedPreferences prefs = await SharedPreferences.getInstance();
await migrateLegacySharedPreferencesToSharedPreferencesAsyncIfNecessary(
legacySharedPreferencesInstance: prefs,
sharedPreferencesAsyncOptions: sharedPreferencesOptions,
migrationCompletedKey: 'migrationCompleted',
);
_asyncPref = SharedPreferencesAsync();
}
}