Home > front end >  Why doesn't FutureBuilder return the Widget?
Why doesn't FutureBuilder return the Widget?

Time:08-26

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

CodePudding user response:

Check that are you getting an white container.

CodePudding user response:

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,
      );
    },
  );
  • Related