I would like to implement something like this picture using Grid View or another way by Flutter.
I implemented to use of GridView.builder
below like codes. But this code doesn’t work like the picture.
Could you give me your idea to express like this picture?
GridView.builder(
itemCount: items.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
),
itemBuilder: (BuildContext context, int index) {
final isDoubleWidth = (index + 1) % 5 == 0;
final itemWidth = isDoubleWidth ? MediaQuery.of(context).size.width / 3 * 2 : MediaQuery.of(context).size.width / 3;
return SizedBox(
width: itemWidth,
child: Text(item[index].title.toString),
);
},
);
3
Answers
With this code, I could make that picture likely.
GridView
does not support something like what you have shown in the picture. If you don’t want to use 3rd party plugins, I suggest you useListView
andRow
widgets to build this UI. You can consider this UI as a list of rows, and each row would contain either 2 or 3 elements. So based on the index of theListView.builder()
‘sitemBuilder
parameter, you can calculate which elements you should show for this list item (the entire row), and from there you can construct your own row usingRow
widget.Just use flutter_staggered_grid_view: ^0.6.2