Skip to content

Commit

Permalink
ptch:Toggle remove and toast
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmittal03 committed Jan 20, 2024
1 parent 95056c5 commit 35f67b7
Showing 1 changed file with 157 additions and 135 deletions.
292 changes: 157 additions & 135 deletions lib/presentation/week_menu/components/DayMenu/menu_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:appetizer/data/core/router/intrinsic_router/intrinsic_router.gr.
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/domain/models/menu/week_menu_tmp.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
import 'package:appetizer/presentation/leaves_and_rebate/bloc/leaves_and_rebate_bloc.dart';
import 'package:appetizer/presentation/week_menu/bloc/week_menu_bloc.dart';
import 'package:appetizer/presentation/components/shadow_container.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_svg_provider/flutter_svg_provider.dart' as svg;
import 'package:fluttertoast/fluttertoast.dart';
import 'package:fswitch_nullsafety/fswitch_nullsafety.dart';
import 'package:intl/intl.dart';
import 'package:appetizer/utils/recase.dart';
Expand Down Expand Up @@ -180,162 +182,182 @@ class MealCard extends StatelessWidget {
required this.dailyItems,
super.key,
});

final Meal meal;
final List<MealItem> dailyItems;

@override
Widget build(BuildContext context) {
String dailyItemsParsed = '';
for (MealItem item in dailyItems) {
dailyItemsParsed += '${item.name.titleCase}, ';
}
dailyItemsParsed =
dailyItemsParsed.substring(0, max(dailyItemsParsed.length - 2, 0));
return ShadowContainer(
offset: 2,
width: 315.toAutoScaledWidth,
height: 170.toAutoScaledHeight,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 125.toAutoScaledWidth,
return BlocBuilder<LeavesAndRebateBloc, LeavesAndRebateState>(
bloc: context.read<LeavesAndRebateBloc>(),
builder: (context, state) {
String dailyItemsParsed = '';
for (MealItem item in dailyItems) {
dailyItemsParsed += '${item.name.titleCase}, ';
}
dailyItemsParsed = dailyItemsParsed.substring(
0, max(dailyItemsParsed.length - 2, 0));
return ShadowContainer(
offset: 2,
width: 315.toAutoScaledWidth,
height: 170.toAutoScaledHeight,
decoration: BoxDecoration(
image: DecorationImage(
image: svg.Svg(
'assets/images/meal_card/${meal.title}.svg',
),
fit: BoxFit.fill,
),
),
child: Column(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
15.toVerticalSizedBox,
Container(
height: 28.toAutoScaledHeight,
padding: 12.toLeftOnlyPadding,
child: Text(
meal.title.titleCase,
style: AppTheme.headline1.copyWith(
fontSize: 20.toAutoScaledFont,
color: AppTheme.black11,
width: 125.toAutoScaledWidth,
height: 170.toAutoScaledHeight,
decoration: BoxDecoration(
image: DecorationImage(
image: svg.Svg(
'assets/images/meal_card/${meal.title}.svg',
),
fit: BoxFit.fill,
),
),
),
Container(
height: 17.toAutoScaledHeight,
padding: EdgeInsets.only(left: 12.toAutoScaledWidth),
child: Text(
'${DateFormat.jm().format(meal.startTime)} - ${DateFormat.jm().format(meal.endTime)}',
style: AppTheme.headline3.copyWith(
fontWeight: FontWeight.w600,
fontSize: 12.toAutoScaledFont,
color: AppTheme.grey2f,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
15.toVerticalSizedBox,
Container(
height: 28.toAutoScaledHeight,
padding: 12.toLeftOnlyPadding,
child: Text(
meal.title.titleCase,
style: AppTheme.headline1.copyWith(
fontSize: 20.toAutoScaledFont,
color: AppTheme.black11,
),
),
),
Container(
height: 17.toAutoScaledHeight,
padding: EdgeInsets.only(left: 12.toAutoScaledWidth),
child: Text(
'${DateFormat.jm().format(meal.startTime)} - ${DateFormat.jm().format(meal.endTime)}',
style: AppTheme.headline3.copyWith(
fontWeight: FontWeight.w600,
fontSize: 12.toAutoScaledFont,
color: AppTheme.grey2f,
),
),
),
10.toVerticalSizedBox,
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding:
EdgeInsets.only(left: 12.toAutoScaledWidth),
child: FittedBox(
fit: BoxFit.contain,
child: BlocSelector<AppBloc, AppState, bool>(
selector: (state) => state.user!.isCheckedOut,
builder: (context, isCheckout) {
return FSwitch(
enable: !meal.isLeaveToggleOutdated &&
!isCheckout &&
(state.remainingLeaves.toString() !=
0.toString()),
open: meal.leaveStatus.status !=
LeaveStatusEnum.P,
sliderColor: AppTheme.customWhite,
openColor: AppTheme.black2e,
height: 20.toAutoScaledHeight,
width: 44.toAutoScaledWidth,
onChanged: (value) async {
if (state.remainingLeaves.toString() ==
'0') {
Fluttertoast.showToast(
msg: 'No remaining leaves!',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return;
}
context
.read<WeekMenuBlocBloc>()
.add(MealLeaveEvent(
meal: meal,
));
},
);
},
),
),
),
],
),
SizedBox(height: 45.toAutoScaledHeight),
FeedbackOrCouponButton(meal: meal),
SizedBox(height: 10.toAutoScaledHeight)
],
),
),
10.toVerticalSizedBox,
Row(
mainAxisAlignment: MainAxisAlignment.start,
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 18.toAutoScaledHeight),
Container(
padding: EdgeInsets.only(left: 12.toAutoScaledWidth),
child: FittedBox(
fit: BoxFit.contain,
child: BlocSelector<AppBloc, AppState, bool>(
selector: (state) => state.user!.isCheckedOut,
builder: (context, isCheckout) {
return FSwitch(
enable:
!meal.isLeaveToggleOutdated && !isCheckout,
open:
meal.leaveStatus.status != LeaveStatusEnum.P,
sliderColor: AppTheme.customWhite,
openColor: AppTheme.black2e,
height: 20.toAutoScaledHeight,
width: 44.toAutoScaledWidth,
onChanged: (value) async {
context
.read<WeekMenuBlocBloc>()
.add(MealLeaveEvent(
meal: meal,
));
},
);
},
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(),
Container(
margin: EdgeInsets.symmetric(
horizontal: 22.toAutoScaledWidth,
),
height: 0.5,
width: 145,
color: AppTheme.rulerColor,
),
SizedBox(height: 8.toAutoScaledHeight),
Container(
width: 187.toAutoScaledWidth,
padding: EdgeInsets.only(
left: 12.toAutoScaledWidth,
right: 19.toAutoScaledWidth,
),
child: RichText(
text: TextSpan(
text: 'Daily Items: ',
style: AppTheme.bodyText2.copyWith(
fontWeight: FontWeight.w600,
color: const Color(0xFFB51111)),
children: [
TextSpan(
text: dailyItemsParsed,
style: AppTheme.bodyText2,
)
],
),
),
),
SizedBox(height: 17.toAutoScaledHeight)
],
),
SizedBox(height: 45.toAutoScaledHeight),
FeedbackOrCouponButton(meal: meal),
SizedBox(height: 10.toAutoScaledHeight)
)
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
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}");
},
),
),
const Spacer(),
Container(
margin: EdgeInsets.symmetric(
horizontal: 22.toAutoScaledWidth,
),
height: 0.5,
width: 145,
color: AppTheme.rulerColor,
),
SizedBox(height: 8.toAutoScaledHeight),
Container(
width: 187.toAutoScaledWidth,
padding: EdgeInsets.only(
left: 12.toAutoScaledWidth,
right: 19.toAutoScaledWidth,
),
child: RichText(
text: TextSpan(
text: 'Daily Items: ',
style: AppTheme.bodyText2.copyWith(
fontWeight: FontWeight.w600,
color: const Color(0xFFB51111)),
children: [
TextSpan(
text: dailyItemsParsed,
style: AppTheme.bodyText2,
)
],
),
),
),
SizedBox(height: 17.toAutoScaledHeight)
],
)
],
),
);
);
});
}
}

Expand Down

0 comments on commit 35f67b7

Please sign in to comment.