diff --git a/lib/presentation/week_menu/components/DayMenu/menu_card.dart b/lib/presentation/week_menu/components/DayMenu/menu_card.dart index 2d42bcf1..eabb47c7 100644 --- a/lib/presentation/week_menu/components/DayMenu/menu_card.dart +++ b/lib/presentation/week_menu/components/DayMenu/menu_card.dart @@ -3,6 +3,7 @@ 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'; @@ -10,6 +11,7 @@ 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'; @@ -180,162 +182,182 @@ class MealCard extends StatelessWidget { required this.dailyItems, super.key, }); + final Meal meal; final List 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( + bloc: context.read(), + 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( + 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() + .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( - 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() - .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) - ], - ) - ], - ), - ); + ); + }); } }