Skip to content

Commit

Permalink
Merge pull request #10 from Divyakumar21202/main
Browse files Browse the repository at this point in the history
"Chore : Added App Filter Logic "
  • Loading branch information
Divyakumar21202 committed Aug 16, 2024
2 parents a59cb15 + 0bfff4e commit 2683713
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 428 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches:
- uiUpdate
- main

jobs:
Build-Apk:
runs-on: ubuntu-latest
Expand Down
25 changes: 24 additions & 1 deletion lib/Global/enums/enums.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';

enum MealTimeType {
breakfast,
lunch,
Expand Down Expand Up @@ -64,5 +66,26 @@ extension MealTimeTypeString on MealTimeType {
case MealTimeType.dinner:
return 'dinner';
}
}


} String intoTitle() {
switch (this) {
case MealTimeType.breakfast:
return 'Breakfast';
case MealTimeType.lunch:
return 'Lunch';
case MealTimeType.dinner:
return 'Dinner';
}
}
IconData getIcon(){
switch (this) {
case MealTimeType.breakfast:
return Icons.free_breakfast;
case MealTimeType.lunch:
return Icons.restaurant;
case MealTimeType.dinner:
return Icons.nightlife;
}
}
}
16 changes: 9 additions & 7 deletions lib/Global/store/app_state_store.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:mess_mgmt/Global/models/user_model.dart';
import 'package:mess_mgmt/features/dashboard/stores/dashboard_store.dart';
import 'package:mobx/mobx.dart';
Expand All @@ -25,12 +24,15 @@ abstract class _AppStateStore with Store {

@action
Future initialization() async {
validateSession();
if(!isExpire){
await dotenv.load(fileName: ".env");
final sp = await SharedPreferences.getInstance();
jwt = sp.getString('JWT');
await dashboardStore.fetchAllMeals();
await validateSession();
if (!isExpire) {
final sp = await SharedPreferences.getInstance();
jwt = sp.getString('JWT');
await dashboardStore.fetchAllMeals();
} else {
jwt = null;
currentUser = null;
isExpire = false;
}
}

Expand Down
33 changes: 33 additions & 0 deletions lib/features/Error Handling/repositories/auth_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

@immutable
abstract class AuthError {
final String errorString;
final String errorDescription;

const AuthError({
required this.errorString,
required this.errorDescription,
});
}

@immutable
class AuthErrorUserNotFound implements AuthError {
const AuthErrorUserNotFound();

@override
String get errorDescription => "The given user was not found on the server!";

@override
String get errorString => "User not exist";
}

@immutable
class AuthErrorEmailAlreadyExist implements AuthError {
const AuthErrorEmailAlreadyExist();
@override
String get errorDescription => "Given emailid Already exist !";

@override
String get errorString => "Email Already Exist";
}
56 changes: 7 additions & 49 deletions lib/features/auth/screens/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:http/http.dart' as http;
import 'package:lottie/lottie.dart';
import 'package:mess_mgmt/Global/Functions/field_validation_function.dart';
import 'package:mess_mgmt/Global/Functions/screen_transition.dart';
Expand All @@ -13,7 +12,6 @@ import 'package:mess_mgmt/Global/widgets/scaffold_messenger.dart';
import 'package:mess_mgmt/features/Networking/widgets/wobbleAppbar.dart';
import 'package:mess_mgmt/features/auth/screens/signup_screen_1.dart';
import 'package:mess_mgmt/features/auth/stores/auth_store.dart';
import 'package:http/http.dart' as http;

class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
Expand Down Expand Up @@ -41,28 +39,17 @@ class _LoginScreenState extends State<LoginScreen> {
}

void login() async {
print('sakfhakhfashf');
if (!isValidate(_emailController.text)) {
showMessage(message: "Enter Valid Email", context: context);
return;
}
showValidateDialog(context, Builder(builder: (context) => Container()));
await Future.delayed(const Duration(seconds: 2));
Map<String, dynamic> data = {
"strategy": "local",
"email": _emailController.text.trim(),
"password": _pwdController.text.trim(),
};

print(data);
// //adding functionality to check the internet connection
bool hasConnection = await checkInternetConnection();
if (!hasConnection) {
showMessage(message: "Check Internet Connection", context: context);
return;
}
// await Future.delayed(const Duration(seconds: 2));

//adding functionality to validate the user input
// bool hasConnection = await checkInternetConnection();
// if (!hasConnection) {
// showMessage(message: "Check Internet Connection", context: context);
// return;
// }
if (_formKey.currentState?.validate() ?? true) {
await authStore.userLogin(
_emailController.text.trim(),
Expand All @@ -83,35 +70,6 @@ class _LoginScreenState extends State<LoginScreen> {
super.dispose();
}

void showValidateDialog(BuildContext context, Builder builder) {
showDialog(
context: context,
builder: (BuildContext context) {

return Dialog(

backgroundColor: Colors.transparent, // Make background transparent
child: BackdropFilter(
filter:
ImageFilter.blur(sigmaX: 10, sigmaY: 10), // Apply blur effect
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color:
Colors.white.withOpacity(0.2), // Slightly opaque background
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white
.withOpacity(0.3), // White border with slight opacity
width: 1.5,
),

),
child: const Text("Successfully logged in"),
)));
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
50 changes: 27 additions & 23 deletions lib/features/dashboard/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:mess_mgmt/Global/models/coupon_model.dart';
import 'package:mess_mgmt/Global/theme/app_theme.dart';
import 'package:mess_mgmt/Global/widgets/loader.dart';
import 'package:mess_mgmt/features/auth/stores/auth_store.dart';
import 'package:mess_mgmt/features/dashboard/screens/shimmerloading.dart';
import 'package:mess_mgmt/features/dashboard/screens/view_screen.dart';
import 'package:mess_mgmt/features/dashboard/stores/dashboard_store.dart';
import 'package:mess_mgmt/features/dashboard/widgets/dashboard_drawer.dart';
Expand Down Expand Up @@ -218,16 +217,29 @@ class _DashboardScreenState extends State<DashboardScreen>
);
}

void navigateToViewScreen(MealTimeType mealTimeType) {
void navigateToViewScreen() {
navigateToNextScreen(
nextScreen: ViewScreen(mealTimeType: mealTimeType), context: context);
nextScreen: const ViewScreen(),
context: context,
);
}

int getCount(MealTimeType type) {
switch (type) {
case MealTimeType.breakfast:
return dashboardStore.totalBreakfastAvailable;
case MealTimeType.lunch:
return dashboardStore.totalLunchAvailable;
case MealTimeType.dinner:
return dashboardStore.totalDinnerAvailable;
}
}

@override
Widget build(BuildContext context) {
/* double widthFactor = MediaQuery.of(context).width; */
return Scaffold(
resizeToAvoidBottomInset: false,
// resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text('Coupon Availability'),
backgroundColor: Theme.of(context).primaryColor,
Expand Down Expand Up @@ -258,28 +270,18 @@ class _DashboardScreenState extends State<DashboardScreen>
children: [
_buildDatePicker(),
const SizedBox(height: 24),
Observer(builder: (context) {
int count = dashboardStore.totalBreakfastAvailable;
return _buildMealCard('Breakfast', Icons.free_breakfast,
count, MealTimeType.breakfast);
}),
const SizedBox(height: 16),
Observer(builder: (context) {
int count = dashboardStore.totalLunchAvailable;
return _buildMealCard(
'Lunch', Icons.restaurant, count, MealTimeType.lunch);
}),
const SizedBox(height: 16),
Observer(builder: (context) {
int count = dashboardStore.totalDinnerAvailable;
return _buildMealCard('Dinner', Icons.nightlife, count,
MealTimeType.dinner);
}),
for (final e in MealTimeType.values) ...[
Observer(builder: (context) {
int count = getCount(e);
return _buildMealCard(
e.intoTitle(), e.getIcon(), count, e);
}),
const SizedBox(height: 16),
],
],
),
),
),
Shimmerloading(),
const Spacer(),
],
),
Expand Down Expand Up @@ -369,7 +371,9 @@ class _DashboardScreenState extends State<DashboardScreen>
),
OutlinedButton(
onPressed: () {
navigateToViewScreen(mealType);
dashboardStore.currentView = mealType;

navigateToViewScreen();
},
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
Expand Down
68 changes: 34 additions & 34 deletions lib/features/dashboard/screens/view_screen.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mess_mgmt/Global/enums/enums.dart';
import 'package:mess_mgmt/Global/enums/pagination_enum.dart';
import 'package:mess_mgmt/Global/models/coupon_data_model.dart';
import 'package:mess_mgmt/Global/widgets/custom_filter_dialog.dart';
import 'package:mess_mgmt/Global/widgets/custom_list_tile.dart';
import 'package:mess_mgmt/features/dashboard/stores/dashboard_store.dart';

class ViewScreen extends StatelessWidget {
const ViewScreen({
super.key,
required this.mealTimeType,
});
final MealTimeType mealTimeType;
const ViewScreen({super.key});

@override
Widget build(BuildContext context) {
List<CouponDataModel> list = [];
switch (mealTimeType) {
case MealTimeType.breakfast:
list = dashboardStore.breakfastList;
break;
case MealTimeType.lunch:
list = dashboardStore.lunchList;
break;
case MealTimeType.dinner:
list = dashboardStore.dinnerList;
break;
}
// List<CouponDataModel> list = [];
// switch (mealTimeType) {
// case MealTimeType.breakfast:
// list = dashboardStore.breakfastList;
// break;
// case MealTimeType.lunch:
// list = dashboardStore.lunchList;
// break;
// case MealTimeType.dinner:
// list = dashboardStore.dinnerList;
// break;
// }

return Scaffold(
appBar: AppBar(
title: Text(mealTimeType.intoString()),
title: Observer(builder: (context) {
return Text(dashboardStore.currentView.intoTitle());
}),
actions: [
TextButton.icon(
onPressed: () {
Expand All @@ -52,20 +49,23 @@ class ViewScreen extends StatelessWidget {
],
),
),
child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
/* ListTile(
title: const Text("SellerName : "),
subtitle: Text('Cost : ${list[index].cost}'),
trailing: Text(list[index].mealType.intoString()),
); */
return GlassyListTile(
coupon: list[index],
i: index,
);
},
),
child: Observer(builder: (context) {
final list = dashboardStore.currentViewList;
return ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
/* ListTile(
title: const Text("SellerName : "),
subtitle: Text('Cost : ${list[index].cost}'),
trailing: Text(list[index].mealType.intoString()),
); */
return GlassyListTile(
coupon: list[index],
i: index,
);
},
);
}),
),
);
}
Expand Down
Loading

0 comments on commit 2683713

Please sign in to comment.