Skip to content

Commit a709737

Browse files
feat: Add the coupon button for chicken days. (#215)
* feat: Add the coupon button for chicken days. * feat: Reduce the size of the button * feat: integrate coupon flow with backend Signed-off-by: Aman <[email protected]> * chor: fix lint issues Signed-off-by: Aman <[email protected]> --------- Signed-off-by: Aman <[email protected]> Co-authored-by: Aman <[email protected]>
1 parent 33a20a3 commit a709737

22 files changed

+602
-216
lines changed

.metadata

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
# This file tracks properties of this Flutter project.
22
# Used by Flutter tool to assess capabilities and perform upgrades etc.
33
#
4-
# This file should be version controlled and should not be manually edited.
4+
# This file should be version controlled.
55

66
version:
7-
revision: 20e59316b8b8474554b38493b8ca888794b0234a
7+
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
88
channel: stable
99

1010
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
17+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
18+
- platform: android
19+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
20+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
21+
- platform: ios
22+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
23+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
24+
- platform: linux
25+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
26+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
27+
- platform: macos
28+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
29+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
30+
- platform: web
31+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
32+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
33+
- platform: windows
34+
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
35+
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

analysis_options.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
include: package:pedantic/analysis_options.yaml
1+
include: package:flutter_lints/flutter.yaml
2+
3+
4+
linter:
5+
rules:
6+
constant_identifier_names: false
7+
prefer_const_constructors: false
8+
avoid_print: false
9+
sized_box_for_whitespace: false
10+
no_leading_underscores_for_local_identifiers: false
11+
library_private_types_in_public_api: false
12+
use_key_in_widget_constructors: false
13+
unnecessary_string_interpolations: false
14+
avoid_function_literals_in_foreach_calls: false
15+
avoid_unnecessary_containers: false
16+
prefer_const_constructors_in_immutables: false
17+
prefer_interpolation_to_compose_strings: false
18+
prefer_typing_uninitialized_variables: false
19+
depend_on_referenced_packages: false
20+

ios/Podfile.lock

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PODS:
3030
- Firebase/RemoteConfig (= 10.3.0)
3131
- firebase_core
3232
- Flutter
33-
- FirebaseABTesting (10.3.0):
33+
- FirebaseABTesting (10.4.0):
3434
- FirebaseCore (~> 10.0)
3535
- FirebaseAnalytics (10.3.0):
3636
- FirebaseAnalytics/AdIdSupport (= 10.3.0)
@@ -54,9 +54,9 @@ PODS:
5454
- FirebaseCoreInternal (~> 10.0)
5555
- GoogleUtilities/Environment (~> 7.8)
5656
- GoogleUtilities/Logger (~> 7.8)
57-
- FirebaseCoreInternal (10.3.0):
57+
- FirebaseCoreInternal (10.4.0):
5858
- "GoogleUtilities/NSData+zlib (~> 7.8)"
59-
- FirebaseInstallations (10.3.0):
59+
- FirebaseInstallations (10.4.0):
6060
- FirebaseCore (~> 10.0)
6161
- GoogleUtilities/Environment (~> 7.8)
6262
- GoogleUtilities/UserDefaults (~> 7.8)
@@ -109,7 +109,7 @@ PODS:
109109
- GoogleUtilities/Network (~> 7.8)
110110
- "GoogleUtilities/NSData+zlib (~> 7.8)"
111111
- nanopb (< 2.30910.0, >= 2.30908.0)
112-
- GoogleDataTransport (9.2.0):
112+
- GoogleDataTransport (9.2.1):
113113
- GoogleUtilities/Environment (~> 7.7)
114114
- nanopb (< 2.30910.0, >= 2.30908.0)
115115
- PromisesObjC (< 3.0, >= 1.2)
@@ -140,8 +140,9 @@ PODS:
140140
- OrderedSet (5.0.0)
141141
- package_info_plus (0.4.5):
142142
- Flutter
143-
- path_provider_ios (0.0.1):
143+
- path_provider_foundation (0.0.1):
144144
- Flutter
145+
- FlutterMacOS
145146
- PromisesObjC (2.1.1)
146147
- ReachabilitySwift (5.0.0)
147148
- Sentry/HybridSDK (7.31.5)
@@ -169,7 +170,7 @@ DEPENDENCIES:
169170
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
170171
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
171172
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
172-
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
173+
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
173174
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
174175
- share_plus (from `.symlinks/plugins/share_plus/ios`)
175176
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`)
@@ -216,8 +217,8 @@ EXTERNAL SOURCES:
216217
:path: ".symlinks/plugins/fluttertoast/ios"
217218
package_info_plus:
218219
:path: ".symlinks/plugins/package_info_plus/ios"
219-
path_provider_ios:
220-
:path: ".symlinks/plugins/path_provider_ios/ios"
220+
path_provider_foundation:
221+
:path: ".symlinks/plugins/path_provider_foundation/ios"
221222
sentry_flutter:
222223
:path: ".symlinks/plugins/sentry_flutter/ios"
223224
share_plus:
@@ -234,32 +235,32 @@ SPEC CHECKSUMS:
234235
firebase_core: bf59c32d2e53814f558efa20840c1902fa2fe461
235236
firebase_messaging: ee597229fc260f8fa491fa8f2d4a32dfbfa406fa
236237
firebase_remote_config: 5007603d4cec2dc1e5016077a7ec36ed93c5041b
237-
FirebaseABTesting: e6660693429b4663573c82f8d2f1041deff1753a
238+
FirebaseABTesting: ae3b32fe26e761fd54c68e37a632a0097b599c87
238239
FirebaseAnalytics: 036232b6a1e2918e5f67572417be1173576245f3
239240
FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a
240-
FirebaseCoreInternal: 29b76f784d607df8b2a1259d73c3f04f1210137b
241-
FirebaseInstallations: e2f26126089dcf41e215f7b8925af8d953c7d602
241+
FirebaseCoreInternal: e301297f4c15a17489e48ed722d733b1578e0c02
242+
FirebaseInstallations: 36b38c733fd37e50857e5e8d74138648f466f18c
242243
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
243244
FirebaseRemoteConfig: c24f767c17b0440ee63c7e93380d599173556113
244245
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
245246
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
246247
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
247248
fluttertoast: eb263d302cc92e04176c053d2385237e9f43fad0
248249
GoogleAppMeasurement: c7d6fff39bf2d829587d74088d582e32d75133c3
249-
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
250+
GoogleDataTransport: ea169759df570f4e37bdee1623ec32a7e64e67c4
250251
GoogleUtilities: c2bdc4cf2ce786c4d2e6b3bcfd599a25ca78f06f
251252
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
252253
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
253254
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
254-
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
255+
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
255256
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
256257
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
257258
Sentry: 4c9babff9034785067c896fd580b1f7de44da020
258-
sentry_flutter: d3dad547d3db4918a8051a5ef738cc195c427b4b
259+
sentry_flutter: b10ae7a5ddcbc7f04648eeb2672b5747230172f1
259260
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
260261
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
261262
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
262-
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
263+
url_launcher_ios: ae1517e5e344f5544fb090b079e11f399dfbe4d2
263264

264265
PODFILE CHECKSUM: 0661a8b4d2adb53671731a5c90a8e5964fc4bf1f
265266

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -220,6 +220,7 @@
220220
};
221221
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
222222
isa = PBXShellScriptBuildPhase;
223+
alwaysOutOfDate = 1;
223224
buildActionMask = 2147483647;
224225
files = (
225226
);
@@ -234,6 +235,7 @@
234235
};
235236
9740EEB61CF901F6004384FC /* Run Script */ = {
236237
isa = PBXShellScriptBuildPhase;
238+
alwaysOutOfDate = 1;
237239
buildActionMask = 2147483647;
238240
files = (
239241
);

ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@
6161
<false/>
6262
<key>io.flutter.embedded_views_preview</key>
6363
<string>YES</string>
64+
<key>UIApplicationSupportsIndirectInputEvents</key>
65+
<true/>
6466
</dict>
6567
</plist>

lib/app_theme.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class AppTheme {
6464
color: blackSecondary,
6565
fontFamily: 'OpenSans',
6666
);
67+
static TextStyle bodyText3 = TextStyle(
68+
fontSize: 10.sp,
69+
fontWeight: FontWeight.w400,
70+
color: blackSecondary,
71+
fontFamily: 'OpenSans',
72+
);
6773
static TextStyle overline = TextStyle(
6874
fontSize: 6.sp,
6975
fontWeight: FontWeight.w400,

lib/locator.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:appetizer/services/analytics_service.dart';
2+
import 'package:appetizer/services/api/coupon_api.dart';
23
import 'package:appetizer/services/api/feedback_api.dart';
34
import 'package:appetizer/services/api/leave_api.dart';
45
import 'package:appetizer/services/api/menu_api.dart';
@@ -45,6 +46,7 @@ import 'package:get_it/get_it.dart';
4546
GetIt locator = GetIt.instance;
4647

4748
Future<void> setupLocator() async {
49+
locator.registerLazySingleton(() => CouponApi());
4850
locator.registerLazySingleton(() => FeedbackApi());
4951
locator.registerLazySingleton(() => LeaveApi());
5052
locator.registerLazySingleton(() => MenuApi());

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: deprecated_member_use
2+
13
import 'package:appetizer/app_theme.dart';
24
import 'package:appetizer/config/environment_config.dart';
35
import 'package:appetizer/firebase_options.dart';

lib/models/menu/week_menu.dart

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,16 @@ class MealItem {
116116
};
117117
}
118118

119-
enum MealItemType { MCL, SLD, EXT, MCD, STR, SNK }
119+
enum MealItemType { MCL, SLD, EXT, MCD, STR, SNK, CPN }
120120

121121
final breakfastTypeValues = EnumValues({
122122
'ext': MealItemType.EXT,
123123
'mcd': MealItemType.MCD,
124124
'mcl': MealItemType.MCL,
125125
'sld': MealItemType.SLD,
126126
'snk': MealItemType.SNK,
127-
'str': MealItemType.STR
127+
'str': MealItemType.STR,
128+
'cpn': MealItemType.CPN,
128129
});
129130

130131
class DayMenu {
@@ -173,6 +174,7 @@ class Meal {
173174
DateTime startTime;
174175
DateTime endTime;
175176
LeaveStatus leaveStatus;
177+
CouponStatus couponStatus;
176178
dynamic wastage;
177179
bool isSwitchable;
178180
SwitchStatus switchStatus;
@@ -200,6 +202,7 @@ class Meal {
200202
required this.isLeaveToggleOutdated,
201203
required this.startDateTime,
202204
required this.endDateTime,
205+
required this.couponStatus,
203206
});
204207

205208
factory Meal.fromJson(Map<String, dynamic> json, DateTime date) => Meal(
@@ -211,6 +214,7 @@ class Meal {
211214
startTime: DateFormat('HH:mm:ss').parse(json['start_time']),
212215
endTime: DateFormat('HH:mm:ss').parse(json['end_time']),
213216
leaveStatus: LeaveStatus.fromJson(json['leave_status']),
217+
couponStatus: CouponStatus.fromJson(json['coupon_status']),
214218
wastage: json['wastage'],
215219
isSwitchable: json['is_switchable'] ?? false,
216220
switchStatus: SwitchStatus.fromJson(json['switch_status']),
@@ -252,6 +256,7 @@ class Meal {
252256
DateTime? startTime,
253257
DateTime? endTime,
254258
LeaveStatus? leaveStatus,
259+
CouponStatus? couponStatus,
255260
dynamic wastage,
256261
bool? isSwitchable,
257262
SwitchStatus? switchStatus,
@@ -270,6 +275,7 @@ class Meal {
270275
startTime: startTime ?? this.startTime,
271276
endTime: endTime ?? this.endTime,
272277
leaveStatus: leaveStatus ?? this.leaveStatus,
278+
couponStatus: couponStatus ?? this.couponStatus,
273279
wastage: wastage ?? this.wastage,
274280
isSwitchable: isSwitchable ?? this.isSwitchable,
275281
switchStatus: switchStatus ?? this.switchStatus,
@@ -321,6 +327,26 @@ class LeaveStatus {
321327
};
322328
}
323329

330+
class CouponStatus {
331+
int? id;
332+
CouponStatusEnum status;
333+
334+
CouponStatus({
335+
this.id,
336+
required this.status,
337+
});
338+
339+
factory CouponStatus.fromJson(Map<String, dynamic>? json) => CouponStatus(
340+
id: json?['id'],
341+
status: couponStatusValues.map[json?['status'] ?? 'N']!,
342+
);
343+
344+
Map<String, dynamic> toJson() => {
345+
'id': id,
346+
'status': couponStatusValues.reverse[status],
347+
};
348+
}
349+
324350
class SwitchStatus {
325351
int id;
326352
SwitchStatusEnum status;
@@ -345,6 +371,13 @@ class SwitchStatus {
345371

346372
enum LeaveStatusEnum { N, A, D, P, U }
347373

374+
enum CouponStatusEnum { N, A }
375+
376+
final couponStatusValues = EnumValues({
377+
'N': CouponStatusEnum.N,
378+
'A': CouponStatusEnum.A,
379+
});
380+
348381
final leaveStatusValues = EnumValues({
349382
'N': LeaveStatusEnum.N,
350383
'A': LeaveStatusEnum.A,

lib/services/api/coupon_api.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:appetizer/config/environment_config.dart';
2+
import 'package:appetizer/constants.dart';
3+
import 'package:appetizer/models/failure_model.dart';
4+
import 'package:appetizer/models/menu/week_menu.dart';
5+
import 'package:appetizer/utils/api_utils.dart';
6+
import 'package:http/http.dart' as http;
7+
8+
class CouponApi {
9+
var headers = {'Content-Type': 'application/json'};
10+
http.Client client = http.Client();
11+
12+
Future<CouponStatus> applyForCoupon(int mealId) async {
13+
var endpoint = '/api/coupon/';
14+
var uri = EnvironmentConfig.BASE_URL + endpoint;
15+
16+
try {
17+
await ApiUtils.addTokenToHeaders(headers);
18+
var jsonResponse =
19+
await ApiUtils.post(uri, headers: headers, body: {'meal': mealId});
20+
21+
return CouponStatus(
22+
status: CouponStatusEnum.A,
23+
id: jsonResponse['id'],
24+
);
25+
} on Exception catch (e) {
26+
print(e.toString());
27+
throw Failure(Constants.GENERIC_FAILURE);
28+
}
29+
}
30+
31+
Future<CouponStatus> cancelCoupon(int couponId) async {
32+
var endpoint = '/api/coupon/$couponId';
33+
var uri = EnvironmentConfig.BASE_URL + endpoint;
34+
35+
try {
36+
await ApiUtils.addTokenToHeaders(headers);
37+
await ApiUtils.delete(uri, headers: headers);
38+
39+
return CouponStatus(status: CouponStatusEnum.N);
40+
} on Exception catch (e) {
41+
print(e.toString());
42+
throw Failure(Constants.GENERIC_FAILURE);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)