-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
148 lines (135 loc) · 4.99 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import 'package:flutter/material.dart';
import './Data/dummy-data.dart';
import './Models/Recipe.dart';
import './Screens/Filters_Screen.dart';
import './Screens/Recipe_Details_Screen.dart';
import './Screens/Tab_Bar_Screen.dart';
import './Screens/Category_Recipes_Screen.dart';
import './Screens/Categories_Screen.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Map<String, bool> _filters = {
'gluten': false,
'lactose': false,
'vegetarian': false,
'vegan': false,
};
List<Recipe> availableRecipes = DUMMY_RECIPES;
List<Recipe> favouriteRecipes = [];
void _setFilters(Map<String, bool> filterData) {
setState(() {
_filters = filterData;
availableRecipes = DUMMY_RECIPES.where((recipe) {
if (_filters['gluten'] == true && recipe.isGlutenFree == false) {
return false;
}
if (_filters['lactose'] == true && recipe.isLactoseFree == false) {
return false;
}
if (_filters['vegetarian'] == true && recipe.isVegetarian == false) {
return false;
}
if (_filters['vegan'] == true && recipe.isVegan == false) {
return false;
}
return true;
}).toList();
});
}
void toggleFavourites(String recipeId) {
final existingIndex = favouriteRecipes.indexWhere(
(recipe) => recipe.id == recipeId,
);
if (existingIndex >= 0) {
setState(() {
favouriteRecipes.removeAt(existingIndex);
});
} else {
setState(() {
favouriteRecipes.add(
DUMMY_RECIPES.firstWhere(
(recipe) => recipe.id == recipeId,
),
);
});
}
}
bool isFavourite(String recipeId) {
return favouriteRecipes.any(
(recipe) => recipe.id == recipeId,
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Meals App',
theme: ThemeData(
primarySwatch: Colors.pink,
accentColor: Colors.amber,
canvasColor: //canvasColor means background color(color of the body)
// Colors.white,
Color.fromRGBO(255, 254, 229, 1), //here, 'O' is the opacity which
//indicates contrast as per my opinion
fontFamily: 'Raleway',
textTheme: ThemeData.light().textTheme.copyWith(
//copyWith is used to add extra features
body1: TextStyle(
color:
// Colors.red,
Color.fromRGBO(20, 51, 51, 1),
),
body2: TextStyle(
color:
// Colors.yellow,
Color.fromRGBO(20, 51, 51, 1),
),
title: TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: 'RobotoCondensed',
fontWeight: FontWeight.bold,
),
),
),
// initialRoute: '/',
home: TabBarScreen(
favouriteRecipes), //The Screen/Widget which is put inside of the the home: named argument
//is declared as homescreen
routes: {
// '/': (_) => TabBarScreen(),
TabBarScreen.routeName: (_) => TabBarScreen(favouriteRecipes),
CategoryRecipesScreen.routeName: (_) =>
CategoryRecipesScreen(availableRecipes),
RecipeDetailsScreen.routeName: (_) =>
RecipeDetailsScreen(toggleFavourites, isFavourite),
FiltersScreen.routeName: (_) => FiltersScreen(
_filters,
_setFilters,
),
}, //routes are used to create routes to the particular screens and naming those routes
onGenerateRoute: (settings) {
//When generating routes dynamically, if the route generated is not mentioned in the
//routes table then onGenerateRoute(as a Default Route) is reached.
print(settings.arguments);
// return MaterialPageRoute(
// builder: (context) => CategoriesScreen(),
// );0
}, //It takes a function which executes for any named navigation action (= pushNamed())
// for which no registered route was found in the routes table. You should return a navigation action (e.g.
//MaterialPageRoute) in onGenerateRoute
onUnknownRoute: (settings) {
//onUnknownRoute is reached when flutter is unable to build
//screen with all other measures taken like on GenerateRoute as a last result or a 'Fallback Page'
//For Eg. 404 page/could not connect to internet Page,etc
return MaterialPageRoute(
builder: (context) => CategoriesScreen(),
);
}, //So,onGenerateRoute executes for any unregistered named route,
// onUnknownRoute executes if onGenerateRoute isn't defined or doesn't return a valid navigation action.
);
}
}