From b4612d342cd8d64fb691ed8653c36fa9161a2d3e Mon Sep 17 00:00:00 2001 From: A-Kashif108 Date: Wed, 27 Dec 2023 12:02:19 +0530 Subject: [PATCH 1/3] feat: leave history impl --- lib/domain/models/leaves/leave.dart | 6 +- .../repositories/leave/leave_repository.dart | 13 +- .../bloc/leaves_and_rebate_bloc.dart | 4 +- .../components/leave_history.dart | 138 +++++++++--------- .../components/DayMenu/menu_card.dart | 31 ++-- 5 files changed, 102 insertions(+), 90 deletions(-) diff --git a/lib/domain/models/leaves/leave.dart b/lib/domain/models/leaves/leave.dart index 465d6962..d3c0c41f 100644 --- a/lib/domain/models/leaves/leave.dart +++ b/lib/domain/models/leaves/leave.dart @@ -7,11 +7,11 @@ class Leave with _$Leave { @JsonSerializable(fieldRename: FieldRename.snake) const factory Leave({ required int id, - required DateTime dateCreated, + required int dateCreated, required String startMealType, required String endMealType, - required DateTime startDatetime, - required DateTime endDatetime, + required int startDatetime, + required int endDatetime, required int mealCount, required String status, }) = _Leave; diff --git a/lib/domain/repositories/leave/leave_repository.dart b/lib/domain/repositories/leave/leave_repository.dart index d63f16c2..9ba859f0 100644 --- a/lib/domain/repositories/leave/leave_repository.dart +++ b/lib/domain/repositories/leave/leave_repository.dart @@ -28,11 +28,20 @@ class LeaveRepository { } Future getLeaves(int year, int month) async { + try { - if (month == 0) return await _apiService.getLeavesForYear(year); - return await _apiService.getLeaves(year, month); + dynamic response; + if (month == 0) { + response = await _apiService.getLeavesForYear(year); + }else{ + + response = await _apiService.getLeaves(year, month); + } + print('response: $response'); + return response; } catch (e) { // TODO: Handle error + print('error: $e'); return const PaginatedLeaves( count: 0, hasNext: false, diff --git a/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart b/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart index e3fc0d28..b2d85dda 100644 --- a/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart +++ b/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart @@ -26,11 +26,11 @@ class LeavesAndRebateBloc FutureOr _onFetchLeavesAndRebates( FetchLeavesAndRebates event, Emitter emit) async { PaginatedLeaves currYearLeaves = - await leaveRepository.getLeaves(DateTime.now().year, 0); + await leaveRepository.getLeaves(DateTime.now().year.toInt(), 0); int remainingLeaves = await leaveRepository.remainingLeaves(); PaginatedYearlyRebate initialYearlyRebates = await transactionRepository.getYearlyRebates( - DateTime(DateTime.now().year, DateTime.now().month - 1).year); + DateTime(DateTime.now().year, DateTime.now().month - 1).year); emit(LeavesAndRebateState( remainingLeaves: remainingLeaves, mealsSkipped: maxLeaves - remainingLeaves, diff --git a/lib/presentation/leaves_and_rebate/components/leave_history.dart b/lib/presentation/leaves_and_rebate/components/leave_history.dart index c7e27125..5c9af72f 100644 --- a/lib/presentation/leaves_and_rebate/components/leave_history.dart +++ b/lib/presentation/leaves_and_rebate/components/leave_history.dart @@ -1,6 +1,7 @@ import 'package:appetizer/app_theme.dart'; import 'package:appetizer/data/core/theme/dimensional/dimensional.dart'; import 'package:appetizer/domain/models/leaves/paginated_leaves.dart'; +import 'package:appetizer/presentation/components/shadow_container.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -10,77 +11,76 @@ class LeaveHistory extends StatelessWidget { @override Widget build(BuildContext context) { + + //TODO: wrap with Shadow Container - return Container( - margin: const EdgeInsets.symmetric(horizontal: 24), - decoration: ShapeDecoration( - color: AppTheme.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15), - ), - shadows: [ - BoxShadow( - color: const Color(0x19000000), - blurRadius: 7.toAutoScaledWidth, - offset: const Offset(2, 2), - spreadRadius: 1, - ) - ]), - child: SingleChildScrollView( - child: ExpansionTile( - expandedCrossAxisAlignment: CrossAxisAlignment.start, - backgroundColor: AppTheme.white, - title: const SizedBox.shrink(), - leading: Text("Leave History", - style: AppTheme.headline3.copyWith( - fontSize: 16.toAutoScaledFont, - color: AppTheme.grey2f, - height: (11.0 / 8.0).toAutoScaledHeight)), - trailing: const Icon(Icons.expand_more, color: AppTheme.grey2f), - children: [ - if (paginatedLeaves.results.isNotEmpty) - Container( - margin: EdgeInsets.only(left: 24.toAutoScaledWidth), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - paginatedLeaves.results[0].startDatetime.year - .toString(), - style: AppTheme.headline2.copyWith( - fontSize: 14.toAutoScaledFont, - color: AppTheme.primary), + return ShadowContainer( + width: 312.toAutoScaledWidth, + offset: 2, + child: ExpansionTile( + + expandedCrossAxisAlignment: CrossAxisAlignment.start, + backgroundColor: AppTheme.white, + title: const SizedBox.shrink(), + leading: Text("Leave History", + style: AppTheme.headline3.copyWith( + fontSize: 16.toAutoScaledFont, + color: AppTheme.grey2f, + height: (11.0 / 8.0).toAutoScaledHeight)), + trailing: const Icon(Icons.expand_more, color: AppTheme.grey2f), + children: [ + if (paginatedLeaves.results.isNotEmpty) + Container( + height: 120, + margin: EdgeInsets.only(left: 24.toAutoScaledWidth), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + // convert int to datetime + DateTime.fromMillisecondsSinceEpoch(paginatedLeaves.results[0].startDatetime).year + .toString(), + style: AppTheme.headline2.copyWith( + fontSize: 14.toAutoScaledFont, + color: AppTheme.primary), + ), + 10.toVerticalSizedBox, + Expanded( + child: ListView( + padding: EdgeInsets.zero, + children: [ + ...paginatedLeaves.results + .map((leave) => Padding( + padding: EdgeInsets.only( + bottom: 10.toAutoScaledHeight), + child: Row( + children: [ + RichText( + text: TextSpan( + text: DateFormat('dd MMM -') + .format(DateTime.fromMillisecondsSinceEpoch(leave.startDatetime)), + style: AppTheme.bodyText1.copyWith( + height: 1.toAutoScaledHeight), + children: [ + TextSpan( + text: leave.startMealType, + style: const TextStyle( + color: AppTheme.primary), + ) + ]), + ), + // const Text("-"), + ], + ), + )) + .toList(), + ], ), - 10.toVerticalSizedBox, - ...paginatedLeaves.results - .map((leave) => Padding( - padding: EdgeInsets.only( - bottom: 10.toAutoScaledHeight), - child: Row( - children: [ - RichText( - text: TextSpan( - text: DateFormat('dd MMM -') - .format(leave.startDatetime), - style: AppTheme.bodyText1.copyWith( - height: 1.toAutoScaledHeight), - children: [ - TextSpan( - text: leave.startMealType, - style: const TextStyle( - color: AppTheme.primary), - ) - ]), - ), - // const Text("-"), - ], - ), - )) - .toList(), - ]), - ) - ], - ), + ), + + ]), + ) + ], ), ); } diff --git a/lib/presentation/week_menu/components/DayMenu/menu_card.dart b/lib/presentation/week_menu/components/DayMenu/menu_card.dart index e35b4de8..1c5993e5 100644 --- a/lib/presentation/week_menu/components/DayMenu/menu_card.dart +++ b/lib/presentation/week_menu/components/DayMenu/menu_card.dart @@ -204,6 +204,7 @@ class MealCard extends StatelessWidget { decoration: BoxDecoration( image: DecorationImage( image: svg.Svg( + meal.type == MealType.S ? 'assets/images/meal_card/Lunch.svg': 'assets/images/meal_card/${meal.title}.svg', ), fit: BoxFit.fill, @@ -283,20 +284,22 @@ class MealCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 18.toAutoScaledHeight), - Container( - constraints: BoxConstraints( - maxHeight: 100.toAutoScaledHeight, - maxWidth: 180.toAutoScaledWidth, - ), - padding: EdgeInsets.only(left: 10.toAutoScaledWidth), - child: ListView.builder( - itemCount: meal.items.length, - shrinkWrap: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final item = meal.items[index]; - return Text("\u2022 ${item.name.titleCase}"); - }, + SingleChildScrollView( + child: Container( + constraints: BoxConstraints( + maxHeight: 100.toAutoScaledHeight, + maxWidth: 180.toAutoScaledWidth, + ), + padding: EdgeInsets.only(left: 10.toAutoScaledWidth), + child: ListView.builder( + itemCount: meal.items.length, + shrinkWrap: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final item = meal.items[index]; + return Text("\u2022 ${item.name.titleCase}"); + }, + ), ), ), const Spacer(), From b5384e1e92f4cdad6583f03863f7772473525ea7 Mon Sep 17 00:00:00 2001 From: A-Kashif108 Date: Wed, 27 Dec 2023 12:12:35 +0530 Subject: [PATCH 2/3] chore: formatting --- .../repositories/leave/leave_repository.dart | 6 +- .../bloc/leaves_and_rebate_bloc.dart | 2 +- .../components/leave_history.dart | 60 ++++++++++--------- .../components/DayMenu/menu_card.dart | 5 +- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/lib/domain/repositories/leave/leave_repository.dart b/lib/domain/repositories/leave/leave_repository.dart index 9ba859f0..5d770fd1 100644 --- a/lib/domain/repositories/leave/leave_repository.dart +++ b/lib/domain/repositories/leave/leave_repository.dart @@ -28,14 +28,12 @@ class LeaveRepository { } Future getLeaves(int year, int month) async { - try { dynamic response; if (month == 0) { response = await _apiService.getLeavesForYear(year); - }else{ - - response = await _apiService.getLeaves(year, month); + } else { + response = await _apiService.getLeaves(year, month); } print('response: $response'); return response; diff --git a/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart b/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart index b2d85dda..a5edab64 100644 --- a/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart +++ b/lib/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart @@ -30,7 +30,7 @@ class LeavesAndRebateBloc int remainingLeaves = await leaveRepository.remainingLeaves(); PaginatedYearlyRebate initialYearlyRebates = await transactionRepository.getYearlyRebates( - DateTime(DateTime.now().year, DateTime.now().month - 1).year); + DateTime(DateTime.now().year, DateTime.now().month - 1).year); emit(LeavesAndRebateState( remainingLeaves: remainingLeaves, mealsSkipped: maxLeaves - remainingLeaves, diff --git a/lib/presentation/leaves_and_rebate/components/leave_history.dart b/lib/presentation/leaves_and_rebate/components/leave_history.dart index 5c9af72f..fa50446c 100644 --- a/lib/presentation/leaves_and_rebate/components/leave_history.dart +++ b/lib/presentation/leaves_and_rebate/components/leave_history.dart @@ -11,14 +11,11 @@ class LeaveHistory extends StatelessWidget { @override Widget build(BuildContext context) { - - //TODO: wrap with Shadow Container return ShadowContainer( width: 312.toAutoScaledWidth, offset: 2, child: ExpansionTile( - expandedCrossAxisAlignment: CrossAxisAlignment.start, backgroundColor: AppTheme.white, title: const SizedBox.shrink(), @@ -38,7 +35,9 @@ class LeaveHistory extends StatelessWidget { children: [ Text( // convert int to datetime - DateTime.fromMillisecondsSinceEpoch(paginatedLeaves.results[0].startDatetime).year + DateTime.fromMillisecondsSinceEpoch( + paginatedLeaves.results[0].startDatetime) + .year .toString(), style: AppTheme.headline2.copyWith( fontSize: 14.toAutoScaledFont, @@ -50,34 +49,37 @@ class LeaveHistory extends StatelessWidget { padding: EdgeInsets.zero, children: [ ...paginatedLeaves.results - .map((leave) => Padding( - padding: EdgeInsets.only( - bottom: 10.toAutoScaledHeight), - child: Row( - children: [ - RichText( - text: TextSpan( - text: DateFormat('dd MMM -') - .format(DateTime.fromMillisecondsSinceEpoch(leave.startDatetime)), - style: AppTheme.bodyText1.copyWith( - height: 1.toAutoScaledHeight), - children: [ - TextSpan( - text: leave.startMealType, - style: const TextStyle( - color: AppTheme.primary), - ) - ]), - ), - // const Text("-"), - ], - ), - )) - .toList(), + .map((leave) => Padding( + padding: EdgeInsets.only( + bottom: 10.toAutoScaledHeight), + child: Row( + children: [ + RichText( + text: TextSpan( + text: DateFormat('dd MMM -') + .format(DateTime + .fromMillisecondsSinceEpoch( + leave.startDatetime)), + style: AppTheme.bodyText1 + .copyWith( + height: + 1.toAutoScaledHeight), + children: [ + TextSpan( + text: leave.startMealType, + style: const TextStyle( + color: AppTheme.primary), + ) + ]), + ), + // const Text("-"), + ], + ), + )) + .toList(), ], ), ), - ]), ) ], diff --git a/lib/presentation/week_menu/components/DayMenu/menu_card.dart b/lib/presentation/week_menu/components/DayMenu/menu_card.dart index 1c5993e5..1f146147 100644 --- a/lib/presentation/week_menu/components/DayMenu/menu_card.dart +++ b/lib/presentation/week_menu/components/DayMenu/menu_card.dart @@ -204,8 +204,9 @@ class MealCard extends StatelessWidget { decoration: BoxDecoration( image: DecorationImage( image: svg.Svg( - meal.type == MealType.S ? 'assets/images/meal_card/Lunch.svg': - 'assets/images/meal_card/${meal.title}.svg', + meal.type == MealType.S + ? 'assets/images/meal_card/Lunch.svg' + : 'assets/images/meal_card/${meal.title}.svg', ), fit: BoxFit.fill, ), From 301127098ccad8c54c4f0a98fdb331a0ecd699a3 Mon Sep 17 00:00:00 2001 From: A-Kashif108 Date: Wed, 27 Dec 2023 12:17:20 +0530 Subject: [PATCH 3/3] chore: removed print --- lib/domain/repositories/leave/leave_repository.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/domain/repositories/leave/leave_repository.dart b/lib/domain/repositories/leave/leave_repository.dart index 5d770fd1..57a0e50b 100644 --- a/lib/domain/repositories/leave/leave_repository.dart +++ b/lib/domain/repositories/leave/leave_repository.dart @@ -35,11 +35,9 @@ class LeaveRepository { } else { response = await _apiService.getLeaves(year, month); } - print('response: $response'); return response; } catch (e) { // TODO: Handle error - print('error: $e'); return const PaginatedLeaves( count: 0, hasNext: false,