Created
December 3, 2019 13:39
-
-
Save Andrious/6a1a34b9b170740a87efdd4fdac06709 to your computer and use it in GitHub Desktop.
Variation of the GridView_Demo
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
// | |
// https://fluttercentral.com/Articles/Post/45 | |
// | |
// Author: Seven Srikanth | |
// | |
// Modified: Greg Perry | |
// | |
import 'package:flutter/material.dart'; | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// TODO: implement build | |
return MaterialApp( | |
home: DefaultTabController( | |
length: 5, | |
child: Scaffold( | |
appBar: AppBar( | |
title: Text('Grid Demo'), | |
bottom: TabBar( | |
tabs: [ | |
Tab( | |
text: 'GridView', | |
), | |
Tab( | |
text: 'GridView.Count', | |
), | |
Tab( | |
text: 'GridView.builder', | |
), | |
Tab( | |
text: 'GridView.custom', | |
), | |
Tab( | |
text: 'GridView.extent', | |
), | |
], | |
isScrollable: true, | |
)), | |
body: TabBarView(children: [ | |
GridView( | |
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( | |
maxCrossAxisExtent: 200.0), | |
children: List.generate(100, sampleContainer), | |
), | |
GridView.count( | |
crossAxisCount: 3, | |
children: List.generate(100, sampleContainer)), | |
GridView.builder( | |
itemCount: 100, | |
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 3), | |
itemBuilder: (_, int index) { | |
return sampleContainer(index); | |
}, | |
), | |
GridView.custom( | |
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 3), | |
childrenDelegate: | |
SliverChildListDelegate(List.generate(100, sampleContainer))), | |
GridView.extent( | |
maxCrossAxisExtent: 200.0, | |
children: List.generate(100, sampleContainer), | |
) | |
]))), | |
); | |
} | |
Widget Function(int index) sampleContainer = (index) { | |
return Container( | |
padding: EdgeInsets.all(20.0), | |
child: Center( | |
child: GridTile( | |
footer: Text( | |
'Item $index', | |
textAlign: TextAlign.center, | |
), | |
header: Text( | |
'SubItem $index', | |
textAlign: TextAlign.center, | |
), | |
child: Icon(Icons.access_alarm, | |
size: 40.0, color: Colors.white30), | |
), | |
), | |
color: Colors.blue[400], | |
margin: EdgeInsets.all(1.0), | |
); | |
}; | |
} | |
void main() { | |
runApp(MyApp()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment