forked from eatvio/eatvio_app
plan creation screen added
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/utils/localization_utils.dart';
|
||||
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||
import 'package:eatvio_app/core/widgets/cpfc_container.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_divider.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/core/widgets/main_background_bouble.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_state.dart';
|
||||
@@ -13,10 +14,9 @@ import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
|
||||
class DayWidget extends StatefulWidget {
|
||||
const DayWidget({
|
||||
DayWidget({
|
||||
super.key,
|
||||
required this.index,
|
||||
});
|
||||
@@ -34,175 +34,250 @@ class _DayWidgetState extends State<DayWidget> {
|
||||
return BlocBuilder<CreateDietCubit, CreateDietState>(
|
||||
builder: (context, state) {
|
||||
return MainBackgroundBouble(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
s.day + ' ${widget.index + 1}',
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CreateDietCubit>().copyDay(widget.index);
|
||||
showInfoToast('${s.day} ${widget.index + 1} ${s.copied}');
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
'assets/icons/copy2.svg',
|
||||
width: 20,
|
||||
height: 24,
|
||||
colorFilter: ColorFilter.mode(appTheme.black, BlendMode.srcIn),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
CustomDivider(),
|
||||
SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
Text(
|
||||
s.day + ' ${widget.index + 1}',
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
s.meal,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
Spacer(),
|
||||
SvgPicture.asset(
|
||||
'assets/icons/copy2.svg',
|
||||
width: 20,
|
||||
height: 24,
|
||||
colorFilter: ColorFilter.mode(appTheme.black, BlendMode.srcIn),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
CustomDivider(),
|
||||
SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
Text(
|
||||
s.meal,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 0,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 1,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 2,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 2;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 3,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 3;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 4,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 4;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final product = state.dietData.dailySchedule?[widget.index][_selectedMealIndex][index];
|
||||
if (product != null) {
|
||||
return _product(
|
||||
index,
|
||||
product.name,
|
||||
product.quantity,
|
||||
getLocalizedMeasurementUnits(
|
||||
s,
|
||||
product.portion,
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 0,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
widget.index,
|
||||
_selectedMealIndex,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
itemCount: state.dietData.dailySchedule?[widget.index][_selectedMealIndex].length ?? 0,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
decoration: BoxDecoration(color: appTheme.gray50, borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
child: SvgPicture.asset(
|
||||
'assets/icons/paste2.svg',
|
||||
width: 28,
|
||||
height: 24,
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 1,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 2,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 2;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 3,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 3;
|
||||
});
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
ChoiceChipWidget(
|
||||
chipsLabelList: chipsLabelList,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
fontSize: TextStyles.textMMedium.fontSize,
|
||||
fontWeight: TextStyles.textMMedium.fontWeight,
|
||||
index: 4,
|
||||
selectedChipIndex: _selectedMealIndex,
|
||||
onSelected: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMealIndex = 4;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () {
|
||||
_modalBottomSheet(
|
||||
dayIndex: widget.index,
|
||||
mealIndex: _selectedMealIndex,
|
||||
createDietCubit: context.read<CreateDietCubit>(),
|
||||
ListView.separated(
|
||||
separatorBuilder: (context, index) => SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
padding: EdgeInsets.all(0),
|
||||
itemBuilder: (context, index) {
|
||||
final product = state.dietData.dailySchedule?[widget.index][_selectedMealIndex][index];
|
||||
if (product != null) {
|
||||
return _product(
|
||||
index,
|
||||
product.name,
|
||||
product.quantity,
|
||||
getLocalizedMeasurementUnits(
|
||||
s,
|
||||
product.portion,
|
||||
),
|
||||
widget.index,
|
||||
_selectedMealIndex,
|
||||
);
|
||||
},
|
||||
text: s.add,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(
|
||||
color: appTheme.whiteA700,
|
||||
),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
),
|
||||
}
|
||||
return null;
|
||||
},
|
||||
itemCount: state.dietData.dailySchedule?[widget.index][_selectedMealIndex].length ?? 0,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CreateDietCubit>().pasteCopiedDay(widget.index);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
decoration: BoxDecoration(color: appTheme.gray50, borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
child: SvgPicture.asset(
|
||||
'assets/icons/paste2.svg',
|
||||
width: 28,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () {
|
||||
_modalBottomSheet(
|
||||
dayIndex: widget.index,
|
||||
mealIndex: _selectedMealIndex,
|
||||
createDietCubit: context.read<CreateDietCubit>(),
|
||||
);
|
||||
},
|
||||
text: s.add,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(
|
||||
color: appTheme.whiteA700,
|
||||
),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
BlocBuilder<CreateDietCubit, CreateDietState>(
|
||||
buildWhen: (previous, current) => previous.dietData.dailySchedule != current.dietData.dailySchedule,
|
||||
builder: (context, state) {
|
||||
if (state.dietData.dailySchedule != null) {
|
||||
final day = state.dietData.dailySchedule?[widget.index];
|
||||
final double calories = day!.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
element.fold(
|
||||
0,
|
||||
(previousValue, element) => previousValue + (element.dailyNutrition?.energy ?? 0),
|
||||
),
|
||||
);
|
||||
|
||||
final double proteins = day.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
element.fold(
|
||||
0,
|
||||
(previousValue, element) => previousValue + (element.dailyNutrition?.proteins ?? 0),
|
||||
),
|
||||
);
|
||||
|
||||
final double fats = day.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
element.fold(
|
||||
0,
|
||||
(previousValue, element) => previousValue + (element.dailyNutrition?.fats ?? 0),
|
||||
),
|
||||
);
|
||||
|
||||
final double carbohydrates = day.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
element.fold(
|
||||
0,
|
||||
(previousValue, element) => previousValue + (element.dailyNutrition?.carbohydrates ?? 0),
|
||||
),
|
||||
);
|
||||
return CpfcContainer(
|
||||
calories: calories,
|
||||
proteins: proteins,
|
||||
fats: fats,
|
||||
carbohydrates: carbohydrates,
|
||||
);
|
||||
}
|
||||
return CpfcContainer(
|
||||
calories: 0,
|
||||
proteins: 0,
|
||||
fats: 0,
|
||||
carbohydrates: 0,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -210,24 +285,26 @@ class _DayWidgetState extends State<DayWidget> {
|
||||
}
|
||||
|
||||
_product(int index, String product, int quantity, String portion, int dayIndex, int mealIndex) {
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
_modalBottomSheet(
|
||||
mealIndex: mealIndex,
|
||||
dayIndex: dayIndex,
|
||||
createDietCubit: context.read<CreateDietCubit>(),
|
||||
portionIndex: index,
|
||||
productNameControllerText: product,
|
||||
quantityControllerText: quantity.toString(),
|
||||
);
|
||||
},
|
||||
trailing: Icon(Icons.more_vert_rounded),
|
||||
title: Text(product),
|
||||
subtitle: Text('$quantity $portion'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
return Material(
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
_modalBottomSheet(
|
||||
mealIndex: mealIndex,
|
||||
dayIndex: dayIndex,
|
||||
createDietCubit: context.read<CreateDietCubit>(),
|
||||
portionIndex: index,
|
||||
productNameControllerText: product,
|
||||
quantityControllerText: quantity.toString(),
|
||||
);
|
||||
},
|
||||
trailing: Icon(Icons.more_vert_rounded),
|
||||
title: Text(product),
|
||||
subtitle: Text('$quantity $portion'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
tileColor: appTheme.gray50,
|
||||
),
|
||||
tileColor: Color(0xFFF6FAFF),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user