initGlobalPersist function

Future<void> initGlobalPersist()

Initial the persistent storage.

Use await initGlobalPersist(); in the main() before runApp().

ex.

Future<void> main() async {
  await initGlobalPersist();
  runApp(
    globalHost(child: MyApp())
  );
}

Implementation

Future<void> initGlobalPersist() async {
  if (_isPersistenceInit == false) {
    WidgetsFlutterBinding
        .ensureInitialized(); // To make sure SharedPreferences works.

    _sharedPreferences = await SharedPreferences.getInstance();
    _isPersistenceInit = true;
  }
}