load method
Retrieves data and updates the data in the model.
You will be notified of model updates at the time they are retrieved.
In addition,
the updated Resuult
can be obtained at the stage where the loading is finished.
Implementation
Future<void> load() async {
if (_loadCompleter != null) {
return loading;
}
_loadCompleter = Completer<void>();
await FirebaseCore.initialize();
FirebaseCore.enqueueTransaction(() async {
if (_loadCompleter == null) {
return;
}
try {
await onLoad();
if (_loadCompleter == null) {
return;
}
await reference.get().then(_handleOnUpdate);
await onDidLoad();
_loadCompleter?.complete();
_loadCompleter = null;
} catch (e) {
_loadCompleter?.completeError(e);
_loadCompleter = null;
} finally {
_loadCompleter?.complete();
_loadCompleter = null;
}
});
return loading;
}