Multiple grid layouts in one screen
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"),
);
},
)
],
),
);
}
}
Since you are reusing some code again and again and takes up some memory. Why don't we generate that lines of codes dynamically? and yeah, i am new in flutter.
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"),
);
},
),