我正在使用自己的API。登录帐户后,我只想提取一次数据。我找到了AsyncMemorizer。
AsyncMemoizer _memorizer = AsyncMemoizer();
我有3个Future功能,它们返回Future。通常,如果没有AsyncMemorizer,它可以正常工作,但在这种情况下,我会出错。
fetchData(Store store) {
return this._memorizer.runOnce(() async {
return await Future.wait([
fCustomer(store),
fList(store),
fCompanies(store)
]);
});
}
@override
Widget build(BuildContext context) {
Store store = StoreProvider.of<AppState>(context);
return FutureBuilder<List<bool>>(
future: this._fetchData(store),
builder: (
context,
AsyncSnapshot<List<bool>> snapshot,
) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
if (snapshot.data.every((result) => result == true)) {
return screen();
}
return Text("Sıqıntı");
},
);
}}
错误:
The following assertion was thrown building HomeScreen(dirty, dependencies: [StoreProvider<AppState>], state: _HomeScreenState#79c31(tickers: tracking 1 ticker)):
type 'Future<dynamic>' is not a subtype of type 'Future<List<bool>>'
答案 0 :(得分:0)
我找到了解决方案。
AsyncMemoizer _memorizer = AsyncMemoizer<List<bool>>();
通用AsyncMemorizer起作用。