Last active
February 27, 2020 04:08
-
-
Save letsar/09fb675097290908f7c2328a0f17cad7 to your computer and use it in GitHub Desktop.
Staggered grid 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'; | |
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; | |
List<StaggeredTile> _staggeredTiles = const <StaggeredTile>[ | |
const StaggeredTile.count(2, 2), | |
const StaggeredTile.count(2, 1), | |
const StaggeredTile.count(1, 2), | |
const StaggeredTile.count(1, 1), | |
const StaggeredTile.count(2, 2), | |
const StaggeredTile.count(1, 2), | |
const StaggeredTile.count(1, 1), | |
const StaggeredTile.count(3, 1), | |
const StaggeredTile.count(1, 1), | |
const StaggeredTile.count(4, 1), | |
]; | |
List<Widget> _tiles = const <Widget>[ | |
const _Example01Tile(Colors.green, Icons.widgets), | |
const _Example01Tile(Colors.lightBlue, Icons.wifi), | |
const _Example01Tile(Colors.amber, Icons.panorama_wide_angle), | |
const _Example01Tile(Colors.brown, Icons.map), | |
const _Example01Tile(Colors.deepOrange, Icons.send), | |
const _Example01Tile(Colors.indigo, Icons.airline_seat_flat), | |
const _Example01Tile(Colors.red, Icons.bluetooth), | |
const _Example01Tile(Colors.pink, Icons.battery_alert), | |
const _Example01Tile(Colors.purple, Icons.desktop_windows), | |
const _Example01Tile(Colors.blue, Icons.radio), | |
]; | |
class Example01 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('Example 01'), | |
), | |
body: new Padding( | |
padding: const EdgeInsets.only(top: 12.0), | |
child: new StaggeredGridView.count( | |
crossAxisCount: 4, | |
staggeredTiles: _staggeredTiles, | |
children: _tiles, | |
mainAxisSpacing: 4.0, | |
crossAxisSpacing: 4.0, | |
padding: const EdgeInsets.all(4.0), | |
))); | |
} | |
} | |
class _Example01Tile extends StatelessWidget { | |
const _Example01Tile(this.backgroundColor, this.iconData); | |
final Color backgroundColor; | |
final IconData iconData; | |
@override | |
Widget build(BuildContext context) { | |
return new Card( | |
color: backgroundColor, | |
child: new InkWell( | |
onTap: () {}, | |
child: new Center( | |
child: new Padding( | |
padding: const EdgeInsets.all(4.0), | |
child: new Icon( | |
iconData, | |
color: Colors.white, | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import 'package:flutter/material.dart';
import 'package:marinepedia_app/src/Mmd_Exams.dart';
import 'package:marinepedia_app/src/Mmdexam.dart';
import 'package:marinepedia_app/utils/marinepediaicons_icons.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
class HomeScreen extends StatefulWidget {
@OverRide
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State{
Material myitems(IconData icon,String heading, int color){
return Material(
color: Colors.deepPurpleAccent,
elevation: 14.0,
shadowColor: Color(0x802196F3),
borderRadius: BorderRadius.circular(24.0),
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//text
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(heading,
style: TextStyle(
color: new Color(color),
fontSize: 20.0,
),
),
),
//Icon
Material(
color: new Color(color),
borderRadius: BorderRadius.circular(24.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Icon(
icon,
color: Colors.deepPurple,
size: 30.0,
),
),
)
],
)
}
Widget appbarTitle = Text("DASHBOARD");
GlobalKey _scaffoldKey = GlobalKey();
@OverRide
Widget build(BuildContext context){
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
leading: IconButton(
icon:Icon(Icons.menu),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
}),
title: appbarTitle,
centerTitle: true,
backgroundColor: Colors.deepPurpleAccent,
actions:[
IconButton(icon: Icon(Icons.scatter_plot), onPressed: () {})
]
),
body: StaggeredGridView.count(
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
padding: EdgeInsets.symmetric(horizontal: 10.0,vertical: 15.0),
children:[
InkWell(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>MmdExams()),
);
},
child: myitems(Icons.graphic_eq,"Recent Updates",0xffffffff),
),
InkWell (
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>MmdExams()),
);
},
child: myitems(Icons.library_books,"MMD Exams",0xffffffff),
),
GestureDetector(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>MmdExams()),
);
},
child: myitems(Icons.border_color,"Blogs",0xffffffff),
),
myitems(Icons.ondemand_video,"Video Tutorials",0xffffffff),
myitems(Icons.chrome_reader_mode,"Calculator",0xffffffff),
myitems(Icons.equalizer,"Quiz",0xffffffff),
myitems(Icons.youtube_searched_for,"Dictionary",0xffffffff),
myitems(Icons.group_add,"Join Marinepedia Community",0xffffffff),
],
staggeredTiles: [
StaggeredTile.extent(2, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(1, 120.0),
StaggeredTile.extent(2, 120.0),
],
),
}
}