Created
February 3, 2020 09:47
Grid View Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MaterialApp(home: MyApp())); | |
} | |
class MyApp extends StatelessWidget { | |
final List<Widget> widgetsList = [ | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('He\'d have you all unravel at the'), | |
color: Colors.teal[100], | |
), | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('Heed not the rabble'), | |
color: Colors.teal[200], | |
), | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('Sound of screams but the'), | |
color: Colors.teal[300], | |
), | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('Who scream'), | |
color: Colors.teal[400], | |
), | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('Revolution is coming...'), | |
color: Colors.teal[500], | |
), | |
Container( | |
padding: const EdgeInsets.all(8), | |
child: const Text('Revolution, they...'), | |
color: Colors.teal[600], | |
) | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Stack')), | |
body: _maxCrossAxisExtentGridView(context, widgetsList)); | |
} | |
Widget _fixedCountGridView(List<Widget> children) { | |
return GridView.count( | |
primary: false, | |
padding: const EdgeInsets.all(16), | |
crossAxisSpacing: 8, | |
mainAxisSpacing: 8, | |
crossAxisCount: 3, | |
children: children); | |
} | |
Widget _maxCrossAxisExtentGridView( | |
BuildContext context, List<Widget> children) { | |
return GridView.extent( | |
primary: false, | |
padding: const EdgeInsets.all(16), | |
crossAxisSpacing: 8, | |
mainAxisSpacing: 8, | |
maxCrossAxisExtent: 150, | |
children: children); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment