Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. // ignore: must_be_immutable
  2. class RecipesDashboard extends StatefulWidget {
  3. @override
  4. _RecipesDashboardState createState() => _RecipesDashboardState();
  5. }
  6.  
  7. class _RecipesDashboardState extends State<RecipesDashboard> {
  8. //Sets the gridview items by Image and Title
  9. List griditems = [
  10. GridItem(imageUrl: "assets/images/Pizza.jpg", title: "Pizza"),
  11. GridItem(imageUrl: "assets/images/burger.jpg", title: "Burgers"),
  12. GridItem(imageUrl: "assets/images/breakfast.jpeg", title: "Breakfast"),
  13. GridItem(imageUrl: "assets/images/Chinese.jpg", title: "Chinese"),
  14. GridItem(imageUrl: "assets/images/Indian.jpg", title: "Indian"),
  15. GridItem(imageUrl: "assets/images/Dessert.jpeg", title: "Desert"),
  16. ];
  17.  
  18. @override
  19. Widget build(BuildContext context) {
  20. return Scaffold(
  21. //App Bar from RecipesAppBar
  22. appBar: MyCustomAppBar(height: 150),
  23.  
  24. //Side menu
  25. drawer: SideMenu(),
  26.  
  27. //Container containing a GridView.buider to build a grid the length of Griditem List.
  28. body: Container(
  29. padding: EdgeInsets.all(15),
  30. child: Container(
  31. //Creates the gridview to show the categories.
  32. child: GridView.builder(
  33. //sets the length of the builder as the length of the list.
  34. itemCount: griditems.length,
  35. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  36. crossAxisCount: 2,
  37. ),
  38. itemBuilder: (context, index) {
  39. //Returns each of the cards to hold the categories from the griditems list.
  40. return Container(
  41. child: Card(
  42. //Creates an onTap gesture
  43. child: GestureDetector(
  44. child: Column(
  45. children: <Widget>[
  46. //image
  47. ClipRRect(
  48. borderRadius: BorderRadius.circular(8),
  49. child: Image.asset(
  50. griditems[index].imageUrl,
  51. fit: BoxFit.cover,
  52. width: 150,
  53. height: 128,
  54. ),
  55. ),
  56. //Title
  57. Container(
  58. padding: EdgeInsets.all(5),
  59. child: Text(
  60. griditems[index].title,
  61. style:
  62. TextStyle(fontFamily: "Roboto", fontSize: 16),
  63. ),
  64. )
  65. ],
  66. ),
  67. onTap: () {
  68. //Material push gets the index of the gridtile and takes the title to the next page
  69. print("Tile " + griditems[index].title);
  70. Navigator.push(
  71. context,
  72. MaterialPageRoute(
  73. builder: (context) => FoodList(),
  74. settings: RouteSettings(
  75. arguments: griditems[index].title,
  76. ),
  77. ),
  78. );
  79. },
  80. ),
  81. ),
  82. );
  83. },
  84. ),
  85. ),
  86. ),
  87.  
  88. //Add to category
  89. floatingActionButton: FloatingActionButton(
  90. onPressed: null,
  91. backgroundColor: AppColors.primaryGreen,
  92. ),
  93. );
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement