Home > Enterprise >  Flutter StreamBuilder Called Data 3times
Flutter StreamBuilder Called Data 3times

Time:05-30

    return Container(
      color: Colors.white,
      child: StreamBuilder<QuerySnapshot>(
          stream: _statusService.getStatus(),
          builder: (context, AsyncSnapshot snapshot) {
            return !snapshot.hasData
                ? CircularProgressIndicator()
                : ListView.builder(
                    itemCount: snapshot.data.docs.length,
                    itemBuilder: (context, index) {
                      DocumentSnapshot movies = snapshot.data.docs[2];
                      return Padding(
                        padding: const EdgeInsets.symmetric(
                          horizontal: 20,
                          vertical: 0,
                        ),
                        child: Padding(
                          padding: const EdgeInsets.symmetric(
                            horizontal: 20,
                            vertical: 0,
                          ),
                          child: Text(
                            "${movies['description']}",
                            style: TextStyle(
                              fontSize: 10,
                              color: Color(0xFF737599),
                            ),
                          ),
                        ),
                      );
                    });
          }),
    );
  }
}

can someone help me i am trying to call some data from firebase but its called 3 times i didn't find any solution i am waiting for your answers

CodePudding user response:

I think your data length was 3 but you only show doc2. For the length of doc 3, data is displayed 3 times.

change

itemCount: snapshot.data.docs.length,

To

itemCount: 1,
  • Related