getInstance static method
Loads and parses the NativeSharedPreferences for this app from disk.
Because this is reading from disk, it shouldn't be awaited in performance-sensitive blocks.
Implementation
static Future<NativeSharedPreferences> getInstance() async {
if (_completer == null) {
final completer = Completer<NativeSharedPreferences>();
try {
final Map<String, Object> preferencesMap =
await _getSharedPreferencesMap();
completer.complete(NativeSharedPreferences._(preferencesMap));
} on Exception catch (e) {
// If there's an error, explicitly return the future with an error.
// then set the completer to null so we can retry.
completer.completeError(e);
final Future<NativeSharedPreferences> sharedPrefsFuture =
completer.future;
_completer = null;
return sharedPrefsFuture;
}
_completer = completer;
}
return _completer!.future;
}