how to reduce number of reads in firebase?

122 views Asked by At

i have created a chat app and everything works fine except two things

1- in fire base store i get too much reads even if i do nothing, for example i just used my chat app for 5 minuets i got around 6000 reads

enter image description here

2- when i chat to any person some messages don't get received, this is an example

enter image description here

enter image description here

the other person(wiliam) did not receive three messages( yeah, k , now).

///////////

this is the stream builder code to display messages

class Streambuild extends StatelessWidget {
  final String roomid;
  Streambuild({@required this.roomid});

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
        stream: _store
            .collection('FCHATROOM')
            .doc(roomid)
            .collection("CHAT")
            .orderBy('time', descending: true)
            .snapshots(),
        builder: (context, snap) {
          if (!snap.hasData) {
            return Center(
              child: Text('No Messages'),
            );
          }
          return Expanded(
            child: ListView.builder(
                itemCount: snap.data.docs.length,
                reverse: true,
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  return Bubblemsg(
                    txt: snap.data.docs[index].data()['message'],
                    sender: snap.data.docs[index].data()['sender'],
                    realtime: snap.data.docs[index].data()['realtime'],
                    isMe: (snap.data.docs[index].data()['sender'] ==
                        _auth.currentUser.email),
                  );
                }),
          );
        });
  }
}

bubble message code:

class Bubblemsg extends StatelessWidget {
  Bubblemsg({this.sender, this.txt, this.isMe, this.realtime});
  final String txt;
  final String sender;
  final bool isMe;
  final String realtime;

  @override
  Widget build(BuildContext context) {
    var myprov = Provider.of<Help>(context, listen: false);
    return Container(
      width: double.infinity,
      child: Bubble(
        elevation: 5,
        padding: BubbleEdges.all(10),
        margin: isMe
            ? BubbleEdges.only(top: 10, right: 5, left: 30)
            : BubbleEdges.only(top: 10, left: 5, right: 30),
        alignment: isMe ? Alignment.topRight : Alignment.topLeft,
        nip: isMe ? BubbleNip.rightTop : BubbleNip.leftTop,
        color: isMe ? myprov.mid : Colors.grey[900],
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            txt != null
                ? txt.startsWith("https://firebasestorage.googleapis.com/v0")
                    ? Imagecontainer(
                        url: txt,
                      )
                    : SelectableText(
                        txt != null ? txt : "",
                        style: TextStyle(
                          color: myprov.word,
                          fontSize: 20,
                        ),
                      )
                : Text(""),
            Padding(
              padding: EdgeInsets.only(top: 10.0),
              child: Text(
                realtime != null ? realtime : "",
                style: TextStyle(fontSize: 15, color: myprov.word),
                textAlign: TextAlign.end,
              ),
            )
          ],
        ),
      ),
    );
  }
}
0

There are 0 answers