forked from abhishh1/flutter_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.flutter_swiggy_menu.dart
215 lines (195 loc) · 6.43 KB
/
16.flutter_swiggy_menu.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import 'package:flutter/material.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:provider/provider.dart';
class KConstantFonts {
static const String poppinsRegular = "Poppins";
static const String poppinsBold = "Poppins-B";
static const String poppinsM = "Poppins-M";
}
class FoodItem {
final String foodTitle;
final IconData foodIcon;
final String foodCategory;
const FoodItem({
required this.foodTitle,
required this.foodIcon,
required this.foodCategory,
});
}
class PopupNotifier extends ChangeNotifier {
List<FoodItem> allDishes = const [
FoodItem(
foodTitle: "Paneer Kadhai",
foodIcon: Icons.food_bank,
foodCategory: "paneer"),
FoodItem(
foodTitle: "Chicken biryani",
foodIcon: Icons.food_bank,
foodCategory: "biryani"),
FoodItem(
foodTitle: "Palak Paneer",
foodIcon: Icons.food_bank,
foodCategory: "paneer"),
FoodItem(
foodTitle: "Poha",
foodIcon: Icons.food_bank,
foodCategory: "breakfast"),
FoodItem(
foodTitle: "Tomato soup",
foodIcon: Icons.food_bank,
foodCategory: "soup"),
FoodItem(
foodTitle: "Garlic soup",
foodIcon: Icons.food_bank,
foodCategory: "soup"),
FoodItem(
foodTitle: "Palak butter",
foodIcon: Icons.food_bank,
foodCategory: "paneer"),
FoodItem(
foodTitle: "Sambar vada",
foodIcon: Icons.food_bank,
foodCategory: "breakfast"),
];
String? selectedDish;
setSelectedDish({required String value}) {
selectedDish = value;
notifyListeners();
}
bool isFoodFiltered = false;
toggleFoodFilter({required bool value}) {
isFoodFiltered = value;
notifyListeners();
}
List<FoodItem> filterdFood = [];
void filterFood() {
filterdFood.clear();
for (FoodItem foodItem in allDishes) {
if (!filterdFood.contains(foodItem)) {
if (selectedDish != null) {
if (foodItem.foodCategory.contains(selectedDish!)) {
filterdFood.add(foodItem);
notifyListeners();
}
}
}
}
}
}
TextStyle boldText = const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
fontFamily: KConstantFonts.poppinsBold,
color: Colors.white);
TextStyle sboldText = const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
fontFamily: KConstantFonts.poppinsBold,
color: Colors.white);
TextStyle mboldText = const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
fontFamily: KConstantFonts.poppinsBold,
color: Colors.white);
TextStyle regulerText = const TextStyle(
fontSize: 12, fontFamily: KConstantFonts.poppinsM, color: Colors.white);
class FlutterSwiggyButtonWidget extends StatelessWidget {
const FlutterSwiggyButtonWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
PopupNotifier popupNotifier({required bool renderUI}) =>
Provider.of<PopupNotifier>(context, listen: renderUI);
List<FoodItem> items = popupNotifier(renderUI: true).isFoodFiltered
? popupNotifier(renderUI: true).filterdFood
: popupNotifier(renderUI: true).allDishes;
pButton({required String title, required double price}) {
return PopupMenuItem<String>(
onTap: () {
popupNotifier(renderUI: false).setSelectedDish(value: title);
popupNotifier(renderUI: false).toggleFoodFilter(value: true);
popupNotifier(renderUI: false).filterFood();
},
value: title,
child: Row(
children: [
Text(title, style: sboldText),
const SizedBox(width: 50),
Text(price.toString(), style: regulerText)
],
));
}
final button = PopupMenuButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
color: bgColorFaint,
child: Chip(
backgroundColor: Colors.deepOrangeAccent,
label: Text("See menu", style: sboldText),
),
itemBuilder: (_) => <PopupMenuItem<String>>[
pButton(title: "paneer", price: 20),
pButton(title: "biryani", price: 40),
pButton(title: "soup", price: 40),
pButton(title: "breakfast", price: 40),
],
onSelected: (_) {});
return Scaffold(
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (popupNotifier(renderUI: true).isFoodFiltered)
ActionChip(
backgroundColor: Colors.red,
label: Text("Clear", style: sboldText),
onPressed: () {
popupNotifier(renderUI: false).toggleFoodFilter(value: false);
}),
button
],
),
backgroundColor: bgColor,
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 30,
width: 30,
child: Image.asset("assets/swiggy.png")),
const SizedBox(width: 6),
Text("Flutter Swiggy Menu", style: mboldText)
],
),
backgroundColor: bgColorFaint),
body: GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
FoodItem item = items[index];
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: bgColorFaint, borderRadius: BorderRadius.circular(25)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(child: Icon(item.foodIcon)),
const SizedBox(height: 10),
Text(item.foodTitle,
textAlign: TextAlign.center, style: boldText),
Chip(
backgroundColor: bgColor,
label: Text(item.foodCategory, style: regulerText))
],
),
),
);
},
),
);
}
}