initialize function

Future<void> initialize()

Description

  • You have to initialize static_sharedpreferences before you can use any of the methods contained in this library.

  • Loads and parses the SharedPreferences for this app from disk. Because this is reading from disk, it shouldn't be awaited in performance-sensitive blocks.

Example

{@tool sample}

import 'package:static_sharedpreferences/static_sharedpreferences.dart' as sp;

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  sp.initialize().whenComplete((){
    print('Done with initialization!');
  });
  ...
}

{@end-tool}

Implementation

Future<void> initialize() async {
  _instance = await SharedPreferences.getInstance();
}