import'package:flutter/material.dart';
import'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
voidmain() {
runApp(MyApp());
}
classMyAppextendsStatelessWidget {
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
primarySwatch:Colors.blue,
visualDensity:VisualDensity.adaptivePlatformDensity,
),
home:MyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
MyHomePage({Key key, this.title}) :super(key: key);
finalString title;
@override_MyHomePageStatecreateState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:Text("Dashboard"),
centerTitle:true,
),
body:StaggeredGridView.count(
crossAxisCount:2, //number of tiles
crossAxisSpacing:12.0, //spaces between your tiles or vertical space
mainAxisSpacing:12.0, //space between two colums or horizontal space
padding:EdgeInsets.symmetric(horizontal:16.0, vertical:8.0),
children:<Widget>[
myItems(Icons.graphic_eq, "TotalView", Colors.orange),
myItems(Icons.bookmark, "Bookmark", Colors.green),
myItems(Icons.notifications, "Notification", Colors.purple),
myItems(Icons.attach_money, "Balance", Colors.blue),
myItems(Icons.settings, "Setting", Colors.amber),
myItems(Icons.group_work, "Groupwork", Colors.indigo),
myItems(Icons.message, "Message", Colors.red),
//newmyItems(Icons.graphic_eq, "TotalView", Colors.orange),
myItems(Icons.bookmark, "Bookmark", Colors.green),
myItems(Icons.message, "Message", Colors.red),
myItems(Icons.notifications, "Notification", Colors.purple),
myItems(Icons.attach_money, "Balance", Colors.blue),
myItems(Icons.school, "Follower", Colors.yellow),
//myItems(Icons.group_work, "Groupwork", Colors.indigo),
],
staggeredTiles: [
StaggeredTile.extent(2,
130.0), //StaggeredTile.extent(crossAxisCellCount, mainAxisExtent) //crossAxisCellCount = how many tile space that perticular tile gonna take ? and mainAxisExtent = the heigh of the tileStaggeredTile.extent(1, 150.0),
StaggeredTile.extent(1, 150.0),
StaggeredTile.extent(1, 150.0),
StaggeredTile.extent(1, 150.0),
StaggeredTile.extent(2, 250.0),
StaggeredTile.extent(2, 120.0),
//newStaggeredTile.extent(1, 300.0),
StaggeredTile.extent(1, 130.0),
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 150.0),
StaggeredTile.extent(1, 140.0),
//StaggeredTile.extent(2, 120.0),
],
),
);
}
}
MaterialmyItems(IconData icon, String heading, color) {
returnMaterial(
color:Colors.white,
elevation:5.0,
shadowColor:Colors.green,
borderRadius:BorderRadius.circular(24.0),
child:Center(
child:Padding(
padding:constEdgeInsets.all(8.0),
child:Row(
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
Column(
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
//TextPadding(
padding:constEdgeInsets.all(8.0),
child:Text(
heading,
style:TextStyle(fontSize:20.0, color: color),
),
),
//iconMaterial(
color: color,
borderRadius:BorderRadius.circular(24.0),
child:Padding(
padding:constEdgeInsets.all(8.0),
child:Icon(
icon,
color:Colors.white,
size:30.0,
),
),
)
],
)
],
),
),
),
);
}
Extra :
dependencies:
flutter_staggered_grid_view: ^0.3.0 #A Flutter staggered grid view which supports multiple columns with rows of varying sizes.
Images in a Row
Preview :
Code :
WidgetImagesInRow=newRow(
//Display images in a row space evently with equal size
mainAxisAlignment:MainAxisAlignment.spaceEvenly,
children: [
for (int i =1; i <=3; i++) //will make 3 Expanded widgets!Expanded(
child:Image.asset("images/wallpaper.jpg"),
),
],
);
Extra :
Modified : Can select a image to focus using flex !
Preview :
Code :
WidgetFocusImagesInRow=newRow(
//Display images in a row giving one image focus.// Default flex value 1;
mainAxisAlignment:MainAxisAlignment.spaceEvenly,
children: [
Expanded(
flex:1,
child:Image.asset("images/wallpaper.jpg"),
),
Expanded(
flex:2,
child:Image.asset("images/img.jpeg"),
),
Expanded(
flex:1,
child:Image.asset("images/wallpaper.jpg"),
),
],
);