Flutter 2 FutureBuilder inside 1 BuildContext

Viewed 28

I think this situation is a little odd. I'm using two FutureBuilders inside one BuildContext. However, the second FutureBuilder is not working, which means the connectionState is always waiting, and I literally have no idea what's going on.

First FutureBuilder inside AppBar()

final appBar = AppBar(title: FutureBuilder(
      future: futureThatWillReturnAString(),
      builder: (context, AsyncSnapshot snapshot) {
           if (snapshot.connectionState == ConnectionState.waiting) {
              return Text("Searching location...");
           }
            return Text(snapshot.data);
      },
 ));

Second FutureBuilder inside Widget build(BuildContext) {}

appBar: appBar,
body: FutureBuilder(
          future: futureThatWillReturnAMap(),
          builder: (context, AsyncSnapshot snapshot) {
               if (snapshot.connectionState == ConnectionState.waiting) {
                  return Text("Loading lists");
               }
                return ListView.builder(...);
          },
 )

Only the AppBar will finish the future, while the second FutureBuilder remains in the loading state. Please tell me if I'm missing something or if there is something wrong in my implementation. Thanks!

0 Answers
Related