i am trying to fetch the data from my firestore collections, that my collection name is messages. but when it running, streambuilder give null value from firebasefirestore stream collection.
firestore stream :
Stream<List<MessageMdl>>? getMyMessage({int? myId}) { try { _firestore .collection('messages') .where('user_one', isEqualTo: myId) .snapshots() .map((event) { var result = event.docs.map<MessageMdl>((e) { return MessageMdl.fromJson(e.data()); }).toList(); result.sort((MessageMdl a, MessageMdl b) => a.createdAt!.compareTo(b.createdAt!)); return result; }); } catch (e) { print(e.toString()); return throw Exception('failed'); } } streambuilder :
StreamBuilder<List<MessageMdl>>( builder: (context, AsyncSnapshot snapshot) { print(snapshot.data); if (snapshot.hasError) { return Center(child: Text('Something went wrong')); } if (snapshot.connectionState == ConnectionState.waiting) { return Center(child: Text("Loading")); } if (snapshot.hasData) { return SingleChildScrollView( child: Column( children: snapshot.data!.map((e) { return Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Container( margin: EdgeInsets.only( right: e.userOne == myId ? 20 : 0, top: 10, left: e.userOne == myId ? 0 : 20, ), padding: EdgeInsets.symmetric( horizontal: 20, vertical: 15), constraints: BoxConstraints( maxWidth: MediaQuery.of(context).size.width * .7), decoration: BoxDecoration( color: e.userOne == myId ? Colors.grey.shade200 : Colors.green, borderRadius: BorderRadius.only( topLeft: Radius.circular(12), topRight: Radius.circular(12), bottomLeft: Radius.circular(12))), child: Text(e.message!), ), ], ); }).toList(), ), ); } else { return Center(child: Text('no data')); } }, stream: MessageServices().getMyMessage(myId: myId), ) and here is what is snapshot.data value when it get printed in streambuilder : 