Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: leave history impl #271

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 7 additions & 2 deletions lib/domain/repositories/leave/leave_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ 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);
}
return response;
} catch (e) {
// TODO: Handle error
return const PaginatedLeaves(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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(
Expand Down
140 changes: 71 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 @@ -11,76 +12,77 @@ 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),
),
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),
)
]),
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("-"),
],
),
// const Text("-"),
],
),
))
.toList(),
]),
)
],
),
))
.toList(),
],
),
),
]),
)
],
),
);
}
Expand Down
34 changes: 19 additions & 15 deletions lib/presentation/week_menu/components/DayMenu/menu_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ class MealCard extends StatelessWidget {
decoration: BoxDecoration(
image: DecorationImage(
image: svg.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,
),
Expand Down Expand Up @@ -283,20 +285,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