I am tring to give height to the childrens of gridview.builder
but it\'s not accepting. I tried by using container but its not working...
please help
You want to use the childAspectRatio
property of the SliverGridDelegate
preferably with MediaQuery
:
class HomePage extends StatelessWidget {
final List<String> items = <String>[
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5",
"Item 6",
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Home')),
body: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 4),
),
itemCount: items.length,
itemBuilder: (context, index) {
return GridTile(child: Text(items[index]));
},
),
);
}
}