forked from eatvio/eatvio_app
feat(my_diets): draft diets fixes
This commit is contained in:
@@ -32,7 +32,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
emit(state.copyWith(isLoading: true, isDietBeingEdited: true));
|
||||
dietId = diet.id;
|
||||
final dailyScheduleWithNutrition = await createDietRepository.getDietPortionsNutrition(diet.id);
|
||||
final countOfDays = dailyScheduleWithNutrition.length;
|
||||
final countOfDays = diet.duration;
|
||||
final List<List<List<DailySchedule>>> dailySchedule = List.generate(countOfDays, (index) => [[], [], [], [], []]);
|
||||
|
||||
for (final dayEntry in dailyScheduleWithNutrition.entries) {
|
||||
@@ -199,7 +199,10 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
if (!_isFromValid()) return null;
|
||||
final authorProfile = await profileRepository.getMyProfile();
|
||||
final imageBytes = (await state.dietData.image?.readAsBytes()) ?? <int>[];
|
||||
final imageInBase64 = base64.encode(imageBytes);
|
||||
String image = base64.encode(imageBytes);
|
||||
if (image.isEmpty && state.dietData.imageUrl != null) {
|
||||
image = state.dietData.imageUrl ?? '';
|
||||
}
|
||||
final carbs = state.dietData.dailySchedule?.map((element) {
|
||||
return element.fold<double>(0, (prev, element) {
|
||||
return prev +
|
||||
@@ -259,7 +262,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
id: 0,
|
||||
name: state.dietData.name ?? '',
|
||||
slug: '',
|
||||
image: imageInBase64,
|
||||
image: image.isNotEmpty ? image : null,
|
||||
duration: state.dietData.duration ?? 0,
|
||||
state: state.dietData.state ?? DietState.active,
|
||||
type: DietType(
|
||||
@@ -340,7 +343,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
|
||||
Future<String?> updateDiet(int dietId) async {
|
||||
if (!_isFromValid()) return 'error';
|
||||
// if (!_isFromValid()) return 'error';
|
||||
try {
|
||||
File? image;
|
||||
if (state.dietData.image != null) {
|
||||
|
||||
Reference in New Issue
Block a user