init method

Future<void> init()

Initializes the SharedPreferences instance asynchronously.

This method must be called before accessing any shared preferences. It is called automatically in the constructor.

await cannot be used in the constructor, so this method allows initialization after object creation.

Implementation

Future<void> init() async {
  prefs = await SharedPreferences.getInstance();
  sharedPrefIsReady = true;
}