Reputation: 712
When creating a GridView like this, the size of the child widget is ignored and the child widget is expanded to fill the width. However, I want to arrange it according to the size of the child widget, but how can I arrange it according to the size of the child widget?
GridView.count(
controller: controller,
shrinkWrap: true,
crossAxisCount: 2,
children: [
Container(
width: 10,
height: 10,
color: Colors.amber,
),
Container(
width: 10,
height: 10,
color: Colors.blue,
),
],
),
Upvotes: 0
Views: 39
Reputation: 3
If you need the dimensions of the child inside the grid view to be mentioned means you should use
return GridView.builder(
padding: const EdgeInsets.only(left: 28, right: 18, top: 22),
itemCount: 2,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 100.0,
crossAxisSpacing: 12.0,
mainAxisSpacing: 12.0,
childAspectRatio: 1.0,
),
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black,
width: 1.0,
)));
});
}
Upvotes: 0