Flutter / Dart / FutureBuilder - 在构建器之后使用逻辑方法

Flutter / Dart / FutureBuilder - Using Logic method after builder

我正在尝试在 Futurebuilder - builder 之后使用包括逻辑的方法。 但我必须将我的快照保存在构建器中并在我的逻辑中使用它。 我看过这个参考 https://github.com/flutter/flutter/issues/16218#issuecomment-403995076

它说'逻辑应该添加到触发未来的地方(例如你的 initState),使用常规的未来逻辑(.then、await 或任何你想使用的)。 '

但我不习惯玩 futurebuilder、initState、await 或 then。

我考虑过使用 addPostFrameCallback。但不知道在哪里使用它以及里面应该放什么。

谁能告诉我更多细节或推荐参考资料??

非常感谢。

in my futurebuilder

  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(...

in my 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++) {

error code

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>

我会调查提供商。您可以设置一个最初加载此数据的提供者。您可以处理此 Class 中的所有逻辑和 Futures,然后使用 Provider.of(... 在 Widget 中访问它,您可以在其中获得具有已应用逻辑的 Future。您还可以拥有Provider 内的一个 bool,在数据加载之前为 false,并在小部件中使用此 bool 到 return 小部件或加载指示器。