Home > Software design >  Limiting the number of ListViewBuilder item in a row and go to next/new row
Limiting the number of ListViewBuilder item in a row and go to next/new row

Time:11-02

How can limit the number of Listviewbuilder items in a row ( for example I want to show 5 items in a row)and then goes to the next row. There are more than 100 item in the list but I want just show 5 item in every line and then goes to the next line. Thank you.

Widget subViewProducts = Container(
  height: 200,
  margin: EdgeInsets.symmetric(horizontal: 5, vertical: 3),
  child: ListView.builder(
    scrollDirection: Axis.horizontal,
    itemCount: cate.length,
    itemBuilder: (context, i) {
      return  Container(
        width: 150,
        padding: EdgeInsets.all(3),
        child:
        ProducttabBar(
          cate[i].name ,
          cate[i].icon,
          cate[i].price,
          cate[i].destion,
          cate[i].quantity,
          5,
          5,
          i,
        ),);

    },
  ),
);
if (cate.isEmpty) {
  cate.addAll(_products);
}

CodePudding user response:

You can use GridView instead of ListView.

GridView.builder(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 5,
 ),

More info here: https://api.flutter.dev/flutter/widgets/GridView/GridView.builder.html

  • Related