load method
Reads documents corresponding to modelQuery.
The return value is a T
object, and the loaded data is available as is.
Once content is loaded, no new loading is performed. Therefore, it can be used in a method that is read any number of times, such as in the build
method of a widget
.
If you wish to reload the file, use the reload method.
modelQueryに対応したドキュメントの読込を行います。
戻り値はT
オブジェクトが返され、そのまま読込済みのデータの利用が可能になります。
一度読み込んだコンテンツに対しては、新しい読込は行われません。そのためWidget
のbuild
メソッド内など何度でも読み出されるメソッド内でも利用可能です。
再読み込みを行いたい場合はreloadメソッドを利用してください。
Implementation
Future<T?> load() async {
if (_loadCompleter != null) {
return loading!;
}
try {
final val = value;
_loadCompleter = Completer<T?>();
if (!loaded) {
final res = await loadRequest();
if (res != null) {
final filtered = _filterOnLoad(res);
if (filtered.isEmpty) {
_value = null;
} else {
_value = await filterOnDidLoad(
fromMap(filtered),
);
}
}
_loaded = true;
}
if (val != value) {
notifyListeners();
}
_loadCompleter?.complete(value);
_loadCompleter = null;
} catch (e) {
_loadCompleter?.completeError(e);
_loadCompleter = null;
rethrow;
} finally {
_loadCompleter?.complete();
_loadCompleter = null;
}
return value;
}