在 Futurebuilder - builder 之后,我正在嘗試使用包括邏輯的方法。但我必須將我的快照保存在構建器中并在我的邏輯中使用它。我看過這個參考https://github.com/flutter/flutter/issues/16218#issuecomment-403995076
它說'應該使用常規的未來邏輯(.then、await 或任何你想使用的東西)將邏輯添加到觸發未來的地方(例如你的 initState)。'
但我不習慣使用futurebuilder、initState、await 或then。
我考慮使用 addPostFrameCallback。但不知道在哪里使用它以及里面應該有什么。
誰能告訴我更多細節或推薦參考?
多謝。
在我的未來建造者中
recipeList() {
return FutureBuilder<Recipes>(
future: recipeController.recipe,
builder: (context, snapshot) {
if (snapshot.hasData) {
recipeController.snapshots = snapshot; // ->> I need it to excute recipeFinder
recipeController.recipeFinder(); // --> Causing Error
return Container(...
在我的 GetxController
late AsyncSnapshot<Recipes> snapshots = AsyncSnapshot.nothing();
...
recipeFinder() async {
avaliableRecipe.clear();
for (int i = 0; i < 1358; i ) {
int count = 0;
results =
snapshots.data!.COOKRCP02.row.elementAt(i).RCPPARTSDTLS.split(',');
for (int j = 0; j < results.length; j ) {
錯誤代碼
E/flutter (24674): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: setState() or markNeedsBuild() called during build.
E/flutter (24674): This Obx widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
E/flutter (24674): The widget on which setState() or markNeedsBuild() was called was:
E/flutter (24674): Obx
E/flutter (24674): The widget which was currently being built when the offending call was made was:
E/flutter (24674): FutureBuilder<Recipes>
uj5u.com熱心網友回復:
我會調查提供者。您可以設定一個最初加載此資料的提供程式。您可以處理該類中的所有邏輯和 Futures,然后使用 Provider.of(... 在 Widget 中訪問它,您可以在其中使用已應用的邏輯獲得 Future。您還可以在 Provider 中有一個 bool在資料加載之前為假,并在小部件中使用此布林值來回傳小部件或加載指示器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/468626.html
