简体   繁体   中英

Flutter: [FirebaseFirestore][I-FST000001] Error closes App when using StreamBuilder and no internet connection

I'm building an App on Flutter which includes a Chat for the users with Firebase. To show the data updates in real time I get the data through a StreamBuilder. Everything works fine, but when I decide to turn off WIFI and Inte.net connection on an Iphone XI get the following error and the app closes ( NOTE that on the emulator none of the errors appear and it doesn't close ):

THE CODE FOR BUILDING THE STREAM BUILDER:

chatList(){
    return StreamBuilder<QuerySnapshot>(
      stream: DatabaseService(uid: FirebaseAuth.instance.currentUser!.uid).getChatInfo(),
      builder: (context, snapshot){
        //make some checks
        if(snapshot.hasData){
          var docs = snapshot.data!.docs;
          if(docs.isNotEmpty){
            return ListView.separated(
              itemCount: docs.length,
              itemBuilder: (context, index) {
                var doc = docs[index];
                return ChatTile(
                  bondName: (doc['bondNames'][0] == userName)?  doc['bondNames'][1] : doc['bondNames'][0], 
                  chatId: doc['chatId'],
                  sender: checkSender(doc['sentById'].toString()),
                  lastMessage: doc['lastMessage'].toString(),
                  elapsedTime: calculateElapsedTime((doc['sentAt'] as Timestamp).toDate()),
                  read: doc['read'],
                  userId: userId ,
                );
              },
              separatorBuilder: (context, index) {
                return const Divider();
              },
            );
          }else{
            return noChatWidget();
          }
        }else{
          return Center(
            child: CircularProgressIndicator(
              color: Theme.of(context).primaryColor,
              )
            );
        }
      },
    );

  }


THE ERROR ON PHYSICAL DEVICE:

+88312 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WatchStream
(102d1d448) Stream error: 'Unavailable: Network connectivity changed'
[   +1 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WriteStream
(102d79128) Stream error: 'Unavailable: Network connectivity changed'
[+16360 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WatchStream
(102d1d448) Stream error: 'Unavailable: Network connectivity changed'
[   +8 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WatchStream
(102d1d448) Stream error: 'Unavailable: DNS resolution failed for
firestore.googleapis.com: UNKNOWN: nodename nor servname provided, or not
known'
[+4007 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WatchStream
(102d1d448) Stream error: 'Unavailable: DNS resolution failed for
firestore.googleapis.com: UNKNOWN: nodename nor servname provided, or not
known'
[  +11 ms] 10.2.0 - [FirebaseFirestore][I-FST000001] WatchStream
(102d1d448) Stream error: 'Unavailable: DNS resolution failed for
firestore.googleapis.com: UNKNOWN: nodename nor servname provided, or not
known'
[+1306 ms] Service protocol connection closed.
[        ] Lost connection to device.
[   +9 ms] DevFS: Deleting filesystem on the device
(file:///private/var/mobile/Containers/Data/Application/4D1F7639-FEF1-4A33
-866E-734CC70BE773/tmp/binderpC3ghF/binder/)
[ +253 ms] Ignored error while cleaning up DevFS: TimeoutException after
0:00:00.250000: Future not completed
[  +22 ms] "flutter run" took 1.660.540ms.
[  +31 ms] ensureAnalyticsSent: 13ms
[   +1 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[   +1 ms] exiting with code 0

I've tried checking for inte.net connection and returning null when there is no connection on the stream builder, but I still get the error crashing the App. I've searched everywhere and I still cannot find why I get the error knowing that Firebase should even give me an Offline option and it only happens on physical device. Thanks!!

use the ConnectionState property of the StreamBuilder to check the state of the stream and show an appropriate message or widget when the stream is in the ConnectionState.none state.

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