How to show list more than 0 up of string in array flutter

Viewed 50

I have a array here and I want to show all of it accepted for the first one as discibe in an image: enter image description here And this is the code:

                  StreamBuilder(
                    stream: FirebaseFirestore.instance
                        .collection("groups")
                        .doc(groupId)
                        .snapshots(),
                    builder:(context, AsyncSnapshot<DocumentSnapshot> snapshot) {
                      var userDocument = snapshot.data?["members"];

                                                                 return  ListView.builder(
                                                                              scrollDirection: Axis.horizontal,
                                                                              physics:const BouncingScrollPhysics(),
                                                                              itemCount: userDocument.length,
                                                                              shrinkWrap:true,
                                                                              itemBuilder:(context, index) {
                                                                      //Where I display all my list of members                                                         
                                                                 return Text(userDocument[index]);
                                       }), 

This is what it's look like in simulator enter image description here But it still displays all of it And I dont want to display the first one

4 Answers

Try the following code:

ListView.builder(
  itemCount: userDocument.length,
  itemBuilder: (BuildContext context, int index) {
    return index == 0 ? Container() : write your code here;
  },
),

Just tell it that the item count is one less, and then access the document one higher index. Like

return  ListView.builder(
  scrollDirection: Axis.horizontal,
  physics:const BouncingScrollPhysics(),
  itemCount: userDocument.length - 1,
  shrinkWrap:true,
  itemBuilder:(context, index) {
  //Where I display all my list of members                                                         
    return Text(userDocument[index + 1]);
}), 

here you can skip the index 0 and display rest

  ListView.builder(
   itemCount: userDocument.length,
   itemBuilder: (BuildContext context, int index) {
    if(index == 0) {
      // return container();
    } else {
      return Text(userDocument[index]);

     }
   },
 ),

You can skip the first index by

StreamBuilder(
    stream: FirebaseFirestore.instance
        .collection("groups")
        .doc(groupId)
        .snapshots(),
    builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
      var userDocument = snapshot.data?["members"];
      if(userDocument.isNotEmpty){
        userDocument.remove(userDocument.first);
      }
      return ListView.builder(
          scrollDirection: Axis.horizontal,
          physics: const BouncingScrollPhysics(),
          itemCount: userDocument.length,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            //Where I display all my list of members                                                         
            return Text(userDocument[index]);
          });
    });
Related