I want the second column of cards to be slightly uneven how can I achieve that. here is the output that I want:
2 Answers
You can use GridView.builder like this
GridView.builder(
padding: EdgeInsets.only(left: 20, right: 20),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 20,
mainAxisSpacing: 8,
childAspectRatio: 0.7,
),
itemCount: 10,
itemBuilder: (context, index) {
return Padding(
padding: (index % 2) == 0 ? EdgeInsets.only(bottom: 15) : EdgeInsets.only(top: 15),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Container(
decoration: BoxDecoration(
color: (index % 2) == 0 ? Colors.red : Colors.green,
borderRadius: BorderRadius.circular(10),
),
),
),
);
},
);
7 Comments
Abhinav Agarwal
thanks, but can I use cards instead of Containers?
Hemal Moradiya
Then wrap container with card and give it same border radius
Hemal Moradiya
I have edited my answer with card, Please take a look.
Abhinav Agarwal
yup that looks good, but if I have to give more padding to the second card then it's just making the size smaller, like if I am changing the value of EdgeInsets.only(top: 15)
Hemal Moradiya
card height depends on
childAspectRatio, make change in this parameter. |
One approach would be to add two columns inside a row:
Row(
children: [
Expanded(
child: Column(
children: [
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
],
),
),
Expanded(
child: Column(
children: [
const SizedBox(
height: 50,
),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
],
),
),
],
);

flutter_staggered_grid_view: ^0.4.0plugin for list layout.