Skip to content

Commit

Permalink
feat: leave history impl
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Kashif108 committed Dec 27, 2023
1 parent 533278c commit b4612d3
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 90 deletions.
6 changes: 3 additions & 3 deletions lib/domain/models/leaves/leave.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions lib/domain/repositories/leave/leave_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ class LeaveRepository {
}

Future<PaginatedLeaves> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class LeavesAndRebateBloc
FutureOr<void> _onFetchLeavesAndRebates(
FetchLeavesAndRebates event, Emitter<LeavesAndRebateState> 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,
Expand Down
138 changes: 69 additions & 69 deletions lib/presentation/leaves_and_rebate/components/leave_history.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(),
]),
)
],
),
),

]),
)
],
),
);
}
Expand Down
31 changes: 17 additions & 14 deletions lib/presentation/week_menu/components/DayMenu/menu_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit b4612d3

Please sign in to comment.