diff --git a/lib/functions/utility/show_snackbar.dart b/lib/functions/utility/show_snackbar.dart index 24dd8795..c836c35c 100644 --- a/lib/functions/utility/show_snackbar.dart +++ b/lib/functions/utility/show_snackbar.dart @@ -7,6 +7,7 @@ void showSnackBar(String message) { rootScaffoldMessengerKey.currentState?.showSnackBar( SnackBar( content: Text(message, style: MyFonts.w500), + duration: const Duration(seconds: 1), ), ); } diff --git a/lib/globals/endpoints.dart b/lib/globals/endpoints.dart index 352bb226..577d179a 100644 --- a/lib/globals/endpoints.dart +++ b/lib/globals/endpoints.dart @@ -1,9 +1,11 @@ class Endpoints { static const baseUrl = String.fromEnvironment('SERVER-URL'); + static const irbsBaseUrl = String.fromEnvironment('IRBS-SERVER-URL'); static const String restaurantURL = "/getAllOutlets"; static const String lastUpdatedURL = "/lastDataUpdate"; static const String contactURL = "/getContacts"; - static const String timetableURL = "https://swc.iitg.ac.in/smartTimetable/get-my-courses"; + static const String timetableURL = + "https://swc.iitg.ac.in/smartTimetable/get-my-courses"; static const String ferryURL = '/ferryTimings'; static const String busURL = '/busTimings'; static const String busStops = '/busstops'; @@ -24,9 +26,11 @@ class Endpoints { static const String foundURL = '/found'; static const String claimItemURL = "/found/claim"; static const String newsURL = "/news"; - static const String githubIssueToken = String.fromEnvironment('GITHUB_ISSUE_TOKEN'); + static const String githubIssueToken = + String.fromEnvironment('GITHUB_ISSUE_TOKEN'); static const apiSecurityKey = String.fromEnvironment('SECURITY-KEY'); - static const feedback = 'https://api.github.com/repos/swciitg/onestop_flutter/issues'; + static const feedback = + 'https://api.github.com/repos/swciitg/onestop_flutter/issues'; static const String upspPost = '/upsp/submit-request'; static const String uploadFileUPSP = "/upsp/file-upload"; static const String guestLogin = "/user/guest/login"; @@ -35,8 +39,13 @@ class Endpoints { static const String userNotifPrefs = "/user/notifs/prefs"; static const String generalNotifications = "/notification"; static const String userNotifications = "/user/notifs"; + static const String messSubChange = "/sub"; + static const String messOpi = "/opi"; static getHeader() { - return {'Content-Type': 'application/json', 'security-key': Endpoints.apiSecurityKey}; + return { + 'Content-Type': 'application/json', + 'security-key': Endpoints.apiSecurityKey + }; } } diff --git a/lib/main.dart b/lib/main.dart index 68a2bb2b..d15b1530 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,8 @@ import 'package:onestop_dev/stores/travel_store.dart'; import 'package:provider/provider.dart'; import 'firebase_options.dart'; +final navigatorKey = GlobalKey(); + void main() async { WidgetsFlutterBinding.ensureInitialized(); await Future.wait([ @@ -68,6 +70,7 @@ class MyApp extends StatelessWidget { ) ], child: MaterialApp( + navigatorKey: navigatorKey, scaffoldMessengerKey: rootScaffoldMessengerKey, debugShowCheckedModeBanner: false, initialRoute: SplashPage.id, diff --git a/lib/pages/food/food_tab.dart b/lib/pages/food/food_tab.dart index 96d69e6f..91813b30 100644 --- a/lib/pages/food/food_tab.dart +++ b/lib/pages/food/food_tab.dart @@ -5,6 +5,7 @@ import 'package:onestop_dev/models/food/restaurant_model.dart'; import 'package:onestop_dev/services/data_provider.dart'; import 'package:onestop_dev/widgets/food/favourite_dishes.dart'; import 'package:onestop_dev/widgets/food/food_search_bar.dart'; +import 'package:onestop_dev/widgets/food/mess/mess_links.dart'; import 'package:onestop_dev/widgets/food/mess/mess_menu.dart'; import 'package:onestop_dev/widgets/food/outlets_filter.dart'; import 'package:onestop_dev/widgets/food/restaurant/restaurant_tile.dart'; @@ -34,7 +35,7 @@ class FoodTab extends StatelessWidget { children: [ MessMenu(), const SizedBox(height: 16), - // const MessLinks(), + const MessLinks(), const SizedBox(height: 16), const FavoriteDishes(), const SizedBox(height: 16), diff --git a/lib/pages/food/mess_opi_form.dart b/lib/pages/food/mess_opi_form.dart index e81eaf00..87053495 100644 --- a/lib/pages/food/mess_opi_form.dart +++ b/lib/pages/food/mess_opi_form.dart @@ -7,9 +7,11 @@ import 'package:onestop_dev/globals/my_colors.dart'; import 'package:onestop_dev/globals/my_fonts.dart'; import 'package:onestop_dev/models/profile/profile_model.dart'; import 'package:onestop_dev/stores/login_store.dart'; +import 'package:onestop_dev/stores/mess_store.dart'; import 'package:onestop_dev/widgets/profile/custom_dropdown.dart'; import 'package:onestop_dev/widgets/profile/custom_text_field.dart'; import 'package:onestop_dev/widgets/ui/simple_button.dart'; +import '../../main.dart'; class MessOpiFormPage extends StatefulWidget { static const id = '/messOpiFormPage'; @@ -23,9 +25,9 @@ class _MessOpiFormPageState extends State { final TextEditingController _commentsController = TextEditingController(); final user = ProfileModel.fromJson(LoginStore.userData); late String selectedHostel; - int breakFastPoints = 0; - int lunchPoints = 0; - int dinnerPoints = 0; + int breakfast = 0; + int lunch = 0; + int dinner = 0; bool isLoading = false; final List hostels = khostels; final List points = [1, 2, 3, 4, 5]; @@ -43,29 +45,57 @@ class _MessOpiFormPageState extends State { void onChangeSelectedHostel(String? hostel) => selectedHostel = hostel!; void onChangeBreakfastPoints(String? points) => - breakFastPoints = int.parse(points!); - void onChangeLunchPoints(String? points) => lunchPoints = int.parse(points!); - void onChangeDinnerPoints(String? points) => - dinnerPoints = int.parse(points!); + breakfast = int.parse(points!); + void onChangeLunchPoints(String? points) => lunch = int.parse(points!); + void onChangeDinnerPoints(String? points) => dinner = int.parse(points!); - void onPressedNext() async { - setState(() { - isLoading = true; - }); - print("Breakfast points: $breakFastPoints"); - print("Lunch points: $lunchPoints"); - print("Dinner points: $dinnerPoints"); - print("Comments: ${_commentsController.text}"); - if (breakFastPoints == 0 || lunchPoints == 0 || dinnerPoints == 0) { - print("user not assigned all fields"); - showSnackBar("Please fill all the compulsory fields"); + void onSubmit() async { + try { + setState(() { + isLoading = true; + }); + if (breakfast == 0 || lunch == 0 || dinner == 0) { + showSnackBar("Please fill all the compulsory fields"); + } + final data = { + "comments": _commentsController.text.trim(), + "hostel": selectedHostel, + "satisfaction": { + "breakfast": breakfast, + "lunch": lunch, + "dinner": dinner, + }, + "userName": user.name, + }; + print(data); + final res = await MessStore().postMessOpi(data); + if (res.containsKey('success')) { + showSnackBar(res['message']); + await Future.delayed(const Duration(seconds: 1)); + setState(() { + isLoading = false; + }); + navigatorKey.currentState!.pop(); + } else if (res.containsKey('errors')) { + showSnackBar((res['errors'] as List).first['message']); + await Future.delayed(const Duration(seconds: 1)); + setState(() { + isLoading = false; + }); + navigatorKey.currentState!.pop(); + } + setState(() { + isLoading = false; + }); + } catch (e) { + final error = e.toString(); + setState(() { + isLoading = false; + }); + if (error.contains('connection error')) { + showSnackBar("No interest connection!"); + } } - // TODO: implement any further actions - // just to check loading bar - await Future.delayed(const Duration(seconds: 2)); - setState(() { - isLoading = false; - }); } @override @@ -75,128 +105,121 @@ class _MessOpiFormPageState extends State { child: Scaffold( backgroundColor: kBackground, appBar: _buildAppBar(context), - body: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (isLoading) - const LinearProgressIndicator( - color: lBlue2, - backgroundColor: lBlue, - ), - _buildInfo(user), - Container( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildFieldTitle( - title: - "1. Which HOSTEL MESS did you subscribe to in $currentMonth?", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: hostels, - hintText: user.hostel ?? hostels.first, - value: user.hostel, - onChanged: onChangeSelectedHostel, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: - "2. How would you rate the following services by the mess caterer", - isNeccessary: true), - const SizedBox(height: 16), - _pointsInfo(), - const SizedBox(height: 16), - _buildFieldTitle( - title: "Overall Satisfaction - Breakfast", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: points.map((e) => e.toString()).toList(), - hintText: 'Points', - onChanged: onChangeBreakfastPoints, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: "Overall Satisfaction - Lunch", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: points.map((e) => e.toString()).toList(), - hintText: 'Points', - onChanged: onChangeLunchPoints, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: "Overall Satisfaction - Dinner", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: points.map((e) => e.toString()).toList(), - hintText: 'Points', - onChanged: onChangeDinnerPoints, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: "Comments (if any)", isNeccessary: false), - const SizedBox(height: 12), - CustomTextField( - controller: _commentsController, - hintText: "Answer", - maxLines: 5, - isNecessary: false, - ), - ], + body: GestureDetector( + onTap: () => FocusScope.of(context).unfocus(), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (isLoading) + const LinearProgressIndicator( + color: lBlue2, + backgroundColor: lBlue, + ), + _buildInfo(user), + Container( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildFieldTitle( + title: + "1. Which HOSTEL MESS did you subscribe to in $currentMonth?", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: hostels, + value: user.hostel, + onChanged: onChangeSelectedHostel, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: + "2. How would you rate the following services by the mess caterer", + isNeccessary: true), + const SizedBox(height: 16), + _pointsInfo(), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Overall Satisfaction - Breakfast", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: points.map((e) => e.toString()).toList(), + hintText: 'Points', + onChanged: onChangeBreakfastPoints, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Overall Satisfaction - Lunch", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: points.map((e) => e.toString()).toList(), + hintText: 'Points', + onChanged: onChangeLunchPoints, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Overall Satisfaction - Dinner", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: points.map((e) => e.toString()).toList(), + hintText: 'Points', + onChanged: onChangeDinnerPoints, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Comments (if any)", isNeccessary: false), + const SizedBox(height: 12), + CustomTextField( + controller: _commentsController, + hintText: "Answer", + maxLines: 5, + isNecessary: false, + ), + const SizedBox(height: 24), + SimpleButton( + height: 60, + label: "Submit", + onTap: () => onSubmit(), + ), + const SizedBox(height: 12), + ], + ), ), - ), - const SizedBox(height: 80), - ], - ), - ), - bottomNavigationBar: Padding( - padding: const EdgeInsets.all(16.0).copyWith(top: 0), - child: SimpleButton( - height: 60, - label: "Next", - onTap: onPressedNext, + ], + ), ), ), ), ); } - Column _pointsInfo() { + Widget _pointsInfo() { final style = MyFonts.w600.size(14).setColor(kWhite).copyWith(height: 20 / 14); - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text("Very Poor (1 Points)", style: style), - Text("Poor (2 Points)", style: style), - Text("Average (3 Points)", style: style), - Text("Good (4 Points)", style: style), - Text("Very Good (5 Points)", style: style), - ], + return Text( + "Very Poor (1 Points)\nPoor (2 Points)\nAverage (3 Points)\nGood (4 Points)\nVery Good (5 Points)", + style: style, ); } diff --git a/lib/pages/food/mess_subscription_change_form.dart b/lib/pages/food/mess_subscription_change_form.dart index b3e51633..5162cf48 100644 --- a/lib/pages/food/mess_subscription_change_form.dart +++ b/lib/pages/food/mess_subscription_change_form.dart @@ -4,8 +4,10 @@ import 'package:onestop_dev/functions/utility/validator.dart'; import 'package:onestop_dev/globals/hostels.dart'; import 'package:onestop_dev/globals/my_colors.dart'; import 'package:onestop_dev/globals/my_fonts.dart'; +import 'package:onestop_dev/main.dart'; import 'package:onestop_dev/models/profile/profile_model.dart'; import 'package:onestop_dev/stores/login_store.dart'; +import 'package:onestop_dev/stores/mess_store.dart'; import 'package:onestop_dev/widgets/profile/custom_dropdown.dart'; import 'package:onestop_dev/widgets/profile/custom_text_field.dart'; import 'package:onestop_dev/widgets/ui/simple_button.dart'; @@ -24,48 +26,74 @@ class _MessSubscriptionPageState extends State { final user = ProfileModel.fromJson(LoginStore.userData); final List hostels = khostels; bool isLoading = false; - late String currentHostel; - late String desiredHostel; + late String hostelFrom; + late String hostelTo; - void onChangeCurrentHostel(String? hostel) => currentHostel = hostel!; - void onChangeDesiredHostel(String? hostel) => desiredHostel = hostel!; + void onChangeCurrentHostel(String? hostel) => hostelFrom = hostel!; + void onChangeDesiredHostel(String? hostel) => hostelTo = hostel!; @override void initState() { - currentHostel = user.hostel ?? hostels.first; - desiredHostel = hostels.first; - _phoneController.text = user.phoneNumber?.toString() ?? "your answer"; + hostelFrom = user.hostel ?? hostels.first; + hostelTo = hostels.first; + _phoneController.text = user.phoneNumber!.toString(); _rollNumberController.text = user.rollNo; super.initState(); } - void onPressedSubmit() async { - setState(() { - isLoading = true; - }); - if (_phoneController.text.length < 10) { - showSnackBar("Provide proper contact number"); - } else if (_rollNumberController.text != user.rollNo) { - showSnackBar("Incorrect Roll Number"); + Future onSubmit() async { + try { + setState(() { + isLoading = true; + }); + if (_phoneController.text.length < 10) { + showSnackBar("Provide proper contact number"); + } else if (_rollNumberController.text != user.rollNo) { + showSnackBar("Incorrect Roll Number"); + } + final data = { + "hostelFrom": hostelFrom, + "hostelTo": hostelTo, + "contact": _phoneController.text, + "rollNumber": user.rollNo, + "userName": user.name, + }; + final res = await MessStore().postMessSubChange(data); + if (res.containsKey('success')) { + showSnackBar(res['message']); + await Future.delayed(const Duration(seconds: 1)); + setState(() { + isLoading = false; + }); + navigatorKey.currentState!.pop(); + } else if (res.containsKey('errors')) { + showSnackBar((res['errors'] as List).first['message']); + await Future.delayed(const Duration(seconds: 1)); + setState(() { + isLoading = false; + }); + navigatorKey.currentState!.pop(); + } + setState(() { + isLoading = false; + }); + } catch (e) { + final error = e.toString(); + setState(() { + isLoading = false; + }); + if (error.contains('connection error')) { + showSnackBar("No interest connection!"); + } } - print("Contact number: ${_phoneController.text}"); - print("Roll no: ${_rollNumberController.text}"); - print("current hostel: ${user.hostel}"); - print("desired hostel: $desiredHostel"); - // TODO: implemting submit action once form is submitted - // to check loading bar - await Future.delayed(const Duration(seconds: 2)); - setState(() { - isLoading = false; - }); } @override Widget build(BuildContext context) { - currentHostel = user.hostel ?? hostels.first; - desiredHostel = hostels.first; + hostelFrom = user.hostel ?? hostels.first; + hostelTo = hostels.first; - final dropDownIcon = const Icon( + const dropDownIcon = Icon( Icons.keyboard_arrow_down_rounded, size: 24, color: kWhite, @@ -75,77 +103,85 @@ class _MessSubscriptionPageState extends State { child: Scaffold( backgroundColor: kBackground, appBar: _buildAppBar(context), - body: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (isLoading) - const LinearProgressIndicator( - color: lBlue2, - backgroundColor: lBlue, - ), - _buildInfo(user), - Container( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildFieldTitle( - title: "Contact Number", isNeccessary: true), - const SizedBox(height: 12), - CustomTextField( - controller: _phoneController, - hintText: "Your answer", - inputType: TextInputType.phone, - isNecessary: false, - ), - const SizedBox(height: 16), - _buildFieldTitle(title: "Roll Number", isNeccessary: true), - const SizedBox(height: 12), - CustomTextField( - controller: _rollNumberController, - hintText: user.rollNo, - inputType: TextInputType.number, - isNecessary: false, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: "Hostel (Currently residing)", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: hostels, - hintText: user.hostel ?? hostels.first, - value: user.hostel, - onChanged: onChangeCurrentHostel, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - _buildFieldTitle( - title: - "In which hostel mess do you want your subscription to be changed:", - isNeccessary: true), - const SizedBox(height: 12), - CustomDropDown( - items: hostels, - hintText: hostels.first, - value: hostels.first, - onChanged: onChangeDesiredHostel, - validator: validatefield, - borderRadius: BorderRadius.circular(24), - isNecessary: false, - icon: dropDownIcon, - ), - const SizedBox(height: 16), - ], + body: GestureDetector( + onTap: () => FocusScope.of(context).unfocus(), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (isLoading) + const LinearProgressIndicator( + color: lBlue2, + backgroundColor: lBlue, + ), + _buildInfo(user), + Container( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildFieldTitle( + title: "Contact Number", isNeccessary: true), + const SizedBox(height: 12), + CustomTextField( + controller: _phoneController, + hintText: "Your answer", + inputType: TextInputType.phone, + isNecessary: false, + counter: true, + maxLength: 10, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Roll Number", isNeccessary: true), + const SizedBox(height: 12), + CustomTextField( + controller: _rollNumberController, + hintText: user.rollNo, + inputType: TextInputType.number, + isNecessary: false, + counter: true, + maxLength: 9, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: "Hostel (Currently residing)", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: hostels, + // hintText: user.hostel ?? hostels.first, + value: user.hostel, + onChanged: onChangeCurrentHostel, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + _buildFieldTitle( + title: + "In which hostel mess do you want your subscription to be changed:", + isNeccessary: true), + const SizedBox(height: 12), + CustomDropDown( + items: hostels, + // hintText: hostels.first, + value: hostels.first, + onChanged: onChangeDesiredHostel, + validator: validatefield, + borderRadius: BorderRadius.circular(24), + isNecessary: false, + icon: dropDownIcon, + ), + const SizedBox(height: 16), + ], + ), ), - ), - const SizedBox(height: 80), - ], + const SizedBox(height: 80), + ], + ), ), ), bottomNavigationBar: Padding( @@ -153,7 +189,7 @@ class _MessSubscriptionPageState extends State { child: SimpleButton( height: 60, label: "Submit", - onTap: onPressedSubmit, + onTap: () => onSubmit(), ), ), ), diff --git a/lib/services/api.dart b/lib/services/api.dart index c96fd85b..fc290408 100644 --- a/lib/services/api.dart +++ b/lib/services/api.dart @@ -1,5 +1,7 @@ +import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; +import 'package:firebase_core/firebase_core.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:onestop_dev/globals/database_strings.dart'; import 'package:onestop_dev/globals/endpoints.dart'; @@ -520,4 +522,60 @@ class APIService { rethrow; } } + + Future> postMessSubChange( + Map data) async { + final bearerToken = await AuthUserHelpers.getAccessToken(); + print("bearer token: $bearerToken"); + final json = jsonEncode(data); + try { + final res = await dio2.post( + Endpoints.irbsBaseUrl + Endpoints.messSubChange, + data: json, + options: Options( + headers: { + 'Accept': 'application/json', + 'Authorization': 'Bearer $bearerToken' + }, + ), + ); + return res.data; + } on DioException catch (e) { + print("Dio exception: ${e.message}"); + if (e.response != null) { + return e.response!.data; + } + rethrow; + } catch (e) { + print(e); + rethrow; + } + } + + Future> postMessOpi(Map data) async { + final bearerToken = await AuthUserHelpers.getAccessToken(); + print("bearer token: $bearerToken"); + try { + final json = jsonEncode(data); + final res = await dio2.post( + Endpoints.irbsBaseUrl + Endpoints.messOpi, + data: json, + options: Options( + headers: { + 'Accept': 'application/json', + 'Authorization': 'Bearer $bearerToken' + }, + ), + ); + return res.data; + } on DioException catch (e) { + if (e.response != null) { + return e.response!.data; + } + rethrow; + } catch (e) { + print(e); + rethrow; + } + } } diff --git a/lib/stores/mess_store.dart b/lib/stores/mess_store.dart index ab6e9dcc..b05fa885 100644 --- a/lib/stores/mess_store.dart +++ b/lib/stores/mess_store.dart @@ -6,7 +6,9 @@ import 'package:onestop_dev/services/api.dart'; import 'package:onestop_dev/services/data_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; part 'mess_store.g.dart'; + class MessStore = _MessStore with _$MessStore; + abstract class _MessStore with Store { _MessStore() { setupReactions(); @@ -27,61 +29,83 @@ abstract class _MessStore with Store { } return "Dinner"; } + @observable - ObservableFuture selectedHostel = ObservableFuture(getSavedHostel()) ; + ObservableFuture selectedHostel = ObservableFuture(getSavedHostel()); @observable - MealType mealData= MealType(id: 'id', mealDescription: 'mealDescription', startTiming: DateTime.now(), endTiming: DateTime.now()); + MealType mealData = MealType( + id: 'id', + mealDescription: 'mealDescription', + startTiming: DateTime.now(), + endTiming: DateTime.now()); @computed bool get hostelLoaded => selectedHostel.status == FutureStatus.fulfilled; @action void setDay(String s) { selectedDay = s; } + @action void setMeal(String s) { selectedMeal = s; } + @action - void setHostel(String s) { + void setHostel(String s) { selectedHostel = ObservableFuture.value(s); print(selectedHostel.value); print("___________________________________"); } + @action - void setmealData(MealType m) { - mealData = m; + void setmealData(MealType m) { + mealData = m; } + void setupReactions() async { - autorun((_) async{ - if(selectedHostel.status == FutureStatus.fulfilled){ + autorun((_) async { + if (selectedHostel.status == FutureStatus.fulfilled) { print("selected hostel"); print(selectedHostel.value); // MealType requiredModel = await APIService().getMealData(selectedHostel.value! , selectedDay, selectedMeal); - MealType requiredModel = await DataProvider.getMealData(hostel:selectedHostel.value!, day: selectedDay,mealType: selectedMeal ); + MealType requiredModel = await DataProvider.getMealData( + hostel: selectedHostel.value!, + day: selectedDay, + mealType: selectedMeal); print(requiredModel.toJson()); setmealData(requiredModel); - }else{ + } else { print("else selected hostel"); // MealType requiredModel = await APIService().getMealData('kameng' , 'Monday', 'Breakfast'); - MealType requiredModel = await DataProvider.getMealData(hostel:'kameng', day: 'monday',mealType: 'breakfast' ); + MealType requiredModel = await DataProvider.getMealData( + hostel: 'kameng', day: 'monday', mealType: 'breakfast'); print(requiredModel.toJson()); setmealData(requiredModel); } }); } - static Future getSavedHostel() async{ + static Future getSavedHostel() async { var prefs = await SharedPreferences.getInstance(); if (prefs.containsKey('hostel')) { - if(prefs.getString('hostel')=="Brahma"){ + if (prefs.getString('hostel') == "Brahma") { return 'Brahmaputra'; + } else if (prefs.getString('hostel') == "Married Scholars") { + return "Kameng"; } - else if(prefs.getString('hostel')=="Married Scholars") - { - return "Kameng"; - } return prefs.getString('hostel') ?? "Kameng"; } return "Kameng"; } -} \ No newline at end of file + + Future> postMessSubChange( + Map data) async { + final res = await APIService().postMessSubChange(data); + return res; + } + + Future> postMessOpi(Map data) async { + final res = await APIService().postMessOpi(data); + return res; + } +}