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

Time:09-20

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

CodePudding user response:

Try the following code:

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

CodePudding user response:

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]);

     }
   },
 ),

CodePudding user response:

You can filter it by index, like this:

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

CodePudding user response:

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]);
}), 
  • Related