简体   繁体   中英

Why doesn't FutureBuilder return the Widget?

I don't get why this FutureBuilder doesn't return the Widget. "TEST" is printed, so the ConnectionState is done. "Null" is not be printed, but i think it doesn't matter. So what is the problem?

  return FutureBuilder(
    future: getData(),
    builder: (context, snapshot) {
      if(snapshot.connectionState == ConnectionState.done) {
        print("TEST");
        if(snapshot.data == null) print("Null");
        return Container(
          height: 90,
          width: 90,
          color: Colors.white,
        );
      return Container(
        height: 30,
        width: 30,
        color: Colors.redAccent,
      );
    },
  );

i dont think it is the getData-function, because i got the data, but for case i leave it here:

getData() async {
return await FirebaseFirestore.instance.doc(reference).get().then(
        (snapshot) => userdata = User.fromJson(snapshot.data()!));

}

In the logs i get the follow error:

1690-1704/system_process E/memtrack: Couldn't load memtrack module

but i think it's something different. I read i can ignore it. Correct me, if this information was wrong Thanks

Check that are you getting an white container.

Change the container color from Colors.white to any other color

    return FutureBuilder(
    future: getData(),
    builder: (context, snapshot) {
      if(snapshot.connectionState == ConnectionState.done) {
        print("TEST");
        if(snapshot.data == null) print("Null");
        return Container(
          height: 90,
          width: 90,
          color: Colors.white, // If you change the color maybe the container get visible
        );
      return Container(
        height: 30,
        width: 30,
        color: Colors.redAccent,
      );
    },
  );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM