0

My streamBuilder on my app is giving me problems. The problems (on the same screen) are different and I will show you what they are.

This is the stream

final uid = FirebaseAuth.instance.currentUser!.uid;
CollectionReference users = FirebaseFirestore.instance.collection('ADS');

StreamBuilder(
stream: users.doc(uid).snapshot
builder: (BuildContext context, AsyncSnapshot snapshot){
*****conditional statements******})

Statements 1 - In this statement all my emulators return the snapshot.hasData condition even if they don't have data. Sometimes also it returns Bad state.

if (snapshot.hasData) {
                      return Container( padding: const EdgeInsets.only(right: 15, left: 15),
                      child: const Text(
                        "You already have an active ad. You can't have a multiple ads!!",
                        style: TextStyle(color: Colors.white),
                      ),
                    );
                  }

if (!snapshot.hasData) {
                    return const Text(
                      "No data found",
                      style: TextStyle(color: Colors.white),
                    );

else return const Text(
                    "OKOkokoK",
                    style: TextStyle(color: Colors.white),
                  );

Statements 2 - This also returns the snapshot.hasData conditions for in all the emulators even when don't have data.

if (snapshot.hasData) {
                    return const Text(
                      "No data found",
                      style: TextStyle(color: Colors.white),
                    );
                  }
return Container(
                    padding: const EdgeInsets.only(right: 15, left:15),
                    child: const Text(
                      "You already have an active ad. You can't have a multiple ads!!",
                      style: TextStyle(color: Colors.white),
                    ),
                  );

This means that the app is taking only the if condition snapshot.hasData, ignoring the rest of the condition. What should I do? I check suggestions from the following links but none helped

Condition does not work when using a streamBuilder in Flutter flutter firebase: Bad State

0 Answers0