StreamBuilder वापस आती है

Aug 31 2020

फायरबेस से जानकारी प्राप्त करने के लिए मुझे अपने ऐप में फायरबेसबेस आईडी का उपयोग करने में कुछ समस्याएं हैं। मैंने tabBar बनाया जो कि स्ट्रीमब्यूल्डर्स के बीच स्विच करता है जो ऑर्केस्ट्रेटचैनेज से लिए गए यूजर आईडी के अनुसार फायरस्टार के डेटा के आधार पर ब्लॉक की एक सूची संग्रहीत करता है।

मेरे कार्य जो डेटा प्राप्त करते हैं:

 getFavSalons(AsyncSnapshot<QuerySnapshot> snapshot) {
return snapshot.data.docs
    .map((doc) => SalonBlock(
          salonName: doc.data()["salonName"],
          location: doc.data()["location"],
          workTime: doc.data()["workTime"],
          rating: doc.data()["rating"],
        ))
    .toList();  }   

  getFavMasters(AsyncSnapshot<QuerySnapshot> snapshot) {
return snapshot.data.docs
    .map((doc) => MasterBlock(
          fullname: doc.data()["fullName"],
          bio: doc.data()["bio"],
          rating: doc.data()["rating"],
        ))
    .toList();   }

TabBarView में मेरी स्ट्रीमबस्टर:

Container(
            height: screenHeight * 0.9,
            width: screenWidth,
            child:
                TabBarView(controller: _controllerTabs, children: <Widget>[
              StreamBuilder(
                  stream: FirebaseAuth.instance.authStateChanges(),
                  builder: (context, AsyncSnapshot<User> snapshot) {
                    if (snapshot.hasData) {
                      return StreamBuilder(
                          stream: FirebaseFirestore.instance
                              .collection("customers")
                              .doc(snapshot.data.uid)
                              .collection("favSalons")
                              .snapshots(),
                          builder: (context,
                              AsyncSnapshot<QuerySnapshot> snapshot) {
                            if (snapshot.hasData) {
                              return Container(
                                margin: EdgeInsets.only(
                                    bottom: screenHeight * 0.33),
                                child: new ListView(
                                  children: getFavSalons(snapshot),
                                ),
                              );
                            }
                            return LoadingSalon();
                          });
                    }
                   return Text("Loading user...");
                  }),
              StreamBuilder(
                  stream: FirebaseAuth.instance.authStateChanges(),
                  builder: (context, AsyncSnapshot<User> snapshot) {
                    if (snapshot.hasData) {
                      return StreamBuilder(
                          stream: FirebaseFirestore.instance
                              .collection("customers")
                              .doc(snapshot.data.uid)
                              .collection("favMasters")
                              .snapshots(),
                          builder: (context,
                              AsyncSnapshot<QuerySnapshot> snapshot) {
                            if (snapshot.hasData) {
                              return Container(
                                margin: EdgeInsets.only(
                                    bottom: screenHeight * 0.33),
                                child: new ListView(
                                  children: getFavMasters(snapshot),
                                ),
                              );
                            }
                            return LoadingSalon();
                          });
                    }
                    return Text("Loading user...");
            ]),

जब मैं अपने ऐप को चलाता हूं तो शुरुआती डेटा ब्लॉक में मौजूद होता है, लेकिन जब मैं टैब के बीच स्विच करने की कोशिश करता हूं तो एक त्रुटि होती है "StreamBuilder वापस अशक्त"। मुझे लगता है कि कुछ परेशानियों के साथ है। मैं इस समस्या को कैसे हल कर सकता हूं?

जवाब

1 galloper Aug 31 2020 at 18:35

ऐसा तब हो सकता है क्योंकि TabBarView आपके टैब को तब स्विच करता है जब आप उन्हें स्विच करते हैं। इस समस्या के अलग-अलग समाधान हैं, उत्तर की नकल न करके उन्हें यहां देखें: टैब दृश्य पृष्ठों के बीच संरक्षित स्थिति