Multiple grid layouts in one screen
Flutter – Build Items of GridView Dynamically To generate items in a GridView programmatically, use GridView. builder() constructor to create GridView. This constructor allows us to specify an item builder function, via itemBuilder property, with the context and index of item as parameters.
Just a ListView
with GridViews
inside, and don't forget the shrinkWrap
true for the GridViews
class MultipleGridView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
Text("Title 1"),
GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemCount: 10,
itemBuilder: (context, index) {
return Container(
color: Colors.blue,
child: Text("index: $index"),
);
},
),
Text("Title 2"),
GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemCount: 10,
itemBuilder: (context, index) {
return Container(
color: Colors.blue,
child: Text("index: $index"),
);
},
),
Text("Title 3"),
GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemCount: 10,
itemBuilder: (context, index) {
return Container(
color: Colors.blue,
child: Text("index: $index"),
);
},
),
Text("Title 4"),
GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemCount: 10,
itemBuilder: (context, index) {
return Container(
color: Colors.blue,
child: Text("index: $index"),
);
},
)
],
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With