feat(diary): consultant comments

This commit is contained in:
Username1548
2025-04-24 04:20:24 +07:00
parent 267cc38a0b
commit 3754d047fb
102 changed files with 6021 additions and 494 deletions

View File

@@ -0,0 +1,80 @@
import 'dart:developer';
import 'package:eatvio_app/features/diary/models/consultant_comment_model.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_state.dart';
import 'package:eatvio_app/features/diary/repositories/diary_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ConsultantCommentsCubit extends Cubit<ConsultantCommentsState> {
final DiaryRepository diaryRepository;
ConsultantCommentsCubit({required this.diaryRepository})
: super(
ConsultantCommentsState(
commentsModel: ConsultantCommentModel(
comment: '',
),
),
);
void setComment(String comment) {
emit(
state.copyWith(
commentsModel: state.commentsModel.copyWith(comment: comment),
dayCommentNeedsToBeFilled: comment.length < 3,
),
);
}
void setMealComment({required int mealNumber, required String comment}) {
if (comment.isEmpty) {
final mealsComments = Map<String, MealCommentModel>.from(state.commentsModel.mealsComments);
mealsComments.remove(mealNumber.toString());
emit(state.copyWith.commentsModel(mealsComments: mealsComments));
return;
}
final mealsComments = Map<String, MealCommentModel>.from(state.commentsModel.mealsComments);
mealsComments[mealNumber.toString()] = MealCommentModel(comment: comment, typeNumber: mealNumber);
emit(state.copyWith.commentsModel(mealsComments: mealsComments));
}
void addPortionComment(PortionCommentModel portionComment) {
final portions = [...state.commentsModel.portions];
portions.add(portionComment);
emit(state.copyWith.commentsModel(portions: portions));
}
void updatePortionComment(PortionCommentModel portionCommentModel) {
if (portionCommentModel.comment.isEmpty) {
final portions = [...state.commentsModel.portions];
final updatedPortions = portions.where((portion) => portion.id != portionCommentModel.id).toList();
emit(state.copyWith.commentsModel(portions: updatedPortions));
return;
}
final portions = [...state.commentsModel.portions];
final updatedPortions = portions.map((portion) {
if (portion.id == portionCommentModel.id) {
return portionCommentModel;
}
return portion;
}).toList();
emit(state.copyWith.commentsModel(portions: updatedPortions));
}
Future<void> submitComments(int diaryId) async {
try {
if (state.commentsModel.comment == null || state.commentsModel.comment!.isEmpty || state.commentsModel.comment!.length < 3) {
emit(state.copyWith(dayCommentNeedsToBeFilled: true));
return;
}
if (state.commentsModel.mealsComments.values.any((element) => element.comment.length < 3)) {
return;
}
if (state.commentsModel.portions.any((element) => element.comment.length < 3)) {
return;
}
await diaryRepository.commentUserDay(diaryId: diaryId, commentModel: state.commentsModel);
} catch (e, st) {
log(e.toString(), stackTrace: st);
}
}
}

View File

@@ -0,0 +1,15 @@
import 'package:eatvio_app/features/diary/models/consultant_comment_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'consultant_comments_state.freezed.dart';
@freezed
class ConsultantCommentsState with _$ConsultantCommentsState {
factory ConsultantCommentsState({
required ConsultantCommentModel commentsModel,
@Default(false) bool dayCommentNeedsToBeFilled
}) = _ConsultantCommentsState;
}

View File

@@ -0,0 +1,190 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'consultant_comments_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$ConsultantCommentsState {
ConsultantCommentModel get commentsModel =>
throw _privateConstructorUsedError;
bool get dayCommentNeedsToBeFilled => throw _privateConstructorUsedError;
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ConsultantCommentsStateCopyWith<ConsultantCommentsState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ConsultantCommentsStateCopyWith<$Res> {
factory $ConsultantCommentsStateCopyWith(ConsultantCommentsState value,
$Res Function(ConsultantCommentsState) then) =
_$ConsultantCommentsStateCopyWithImpl<$Res, ConsultantCommentsState>;
@useResult
$Res call(
{ConsultantCommentModel commentsModel, bool dayCommentNeedsToBeFilled});
$ConsultantCommentModelCopyWith<$Res> get commentsModel;
}
/// @nodoc
class _$ConsultantCommentsStateCopyWithImpl<$Res,
$Val extends ConsultantCommentsState>
implements $ConsultantCommentsStateCopyWith<$Res> {
_$ConsultantCommentsStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? commentsModel = null,
Object? dayCommentNeedsToBeFilled = null,
}) {
return _then(_value.copyWith(
commentsModel: null == commentsModel
? _value.commentsModel
: commentsModel // ignore: cast_nullable_to_non_nullable
as ConsultantCommentModel,
dayCommentNeedsToBeFilled: null == dayCommentNeedsToBeFilled
? _value.dayCommentNeedsToBeFilled
: dayCommentNeedsToBeFilled // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ConsultantCommentModelCopyWith<$Res> get commentsModel {
return $ConsultantCommentModelCopyWith<$Res>(_value.commentsModel, (value) {
return _then(_value.copyWith(commentsModel: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ConsultantCommentsStateImplCopyWith<$Res>
implements $ConsultantCommentsStateCopyWith<$Res> {
factory _$$ConsultantCommentsStateImplCopyWith(
_$ConsultantCommentsStateImpl value,
$Res Function(_$ConsultantCommentsStateImpl) then) =
__$$ConsultantCommentsStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{ConsultantCommentModel commentsModel, bool dayCommentNeedsToBeFilled});
@override
$ConsultantCommentModelCopyWith<$Res> get commentsModel;
}
/// @nodoc
class __$$ConsultantCommentsStateImplCopyWithImpl<$Res>
extends _$ConsultantCommentsStateCopyWithImpl<$Res,
_$ConsultantCommentsStateImpl>
implements _$$ConsultantCommentsStateImplCopyWith<$Res> {
__$$ConsultantCommentsStateImplCopyWithImpl(
_$ConsultantCommentsStateImpl _value,
$Res Function(_$ConsultantCommentsStateImpl) _then)
: super(_value, _then);
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? commentsModel = null,
Object? dayCommentNeedsToBeFilled = null,
}) {
return _then(_$ConsultantCommentsStateImpl(
commentsModel: null == commentsModel
? _value.commentsModel
: commentsModel // ignore: cast_nullable_to_non_nullable
as ConsultantCommentModel,
dayCommentNeedsToBeFilled: null == dayCommentNeedsToBeFilled
? _value.dayCommentNeedsToBeFilled
: dayCommentNeedsToBeFilled // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
class _$ConsultantCommentsStateImpl implements _ConsultantCommentsState {
_$ConsultantCommentsStateImpl(
{required this.commentsModel, this.dayCommentNeedsToBeFilled = false});
@override
final ConsultantCommentModel commentsModel;
@override
@JsonKey()
final bool dayCommentNeedsToBeFilled;
@override
String toString() {
return 'ConsultantCommentsState(commentsModel: $commentsModel, dayCommentNeedsToBeFilled: $dayCommentNeedsToBeFilled)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ConsultantCommentsStateImpl &&
(identical(other.commentsModel, commentsModel) ||
other.commentsModel == commentsModel) &&
(identical(other.dayCommentNeedsToBeFilled,
dayCommentNeedsToBeFilled) ||
other.dayCommentNeedsToBeFilled == dayCommentNeedsToBeFilled));
}
@override
int get hashCode =>
Object.hash(runtimeType, commentsModel, dayCommentNeedsToBeFilled);
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ConsultantCommentsStateImplCopyWith<_$ConsultantCommentsStateImpl>
get copyWith => __$$ConsultantCommentsStateImplCopyWithImpl<
_$ConsultantCommentsStateImpl>(this, _$identity);
}
abstract class _ConsultantCommentsState implements ConsultantCommentsState {
factory _ConsultantCommentsState(
{required final ConsultantCommentModel commentsModel,
final bool dayCommentNeedsToBeFilled}) = _$ConsultantCommentsStateImpl;
@override
ConsultantCommentModel get commentsModel;
@override
bool get dayCommentNeedsToBeFilled;
/// Create a copy of ConsultantCommentsState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ConsultantCommentsStateImplCopyWith<_$ConsultantCommentsStateImpl>
get copyWith => throw _privateConstructorUsedError;
}

View File

@@ -2,6 +2,9 @@ import 'dart:developer';
import 'dart:io';
import 'package:eatvio_app/core/image_compressing/image_compress_utility.dart';
import 'package:eatvio_app/core/utils/date_time_utils.dart';
import 'package:eatvio_app/features/consultations/models/consultation_model.dart';
import 'package:eatvio_app/features/diary/models/consultant_review_model.dart';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
@@ -16,12 +19,17 @@ class DiaryCubit extends Cubit<DiaryState> {
late int selectedMeal;
final DiaryRepository diaryRepository;
final GlossaryRepository glossaryRepository;
int? diaryId;
DiaryCubit({required this.diaryRepository, required this.glossaryRepository}) : super(const DiaryState.loading()) {
today = DateTime.now();
selectedDay = today;
diaryRepository.forceFetchStream.listen((_) {
fetchDiary(true, diaryId);
});
}
String comment = '';
setSelectedDay(DateTime day) async {
selectedDay = day;
await fetchDiary(true);
@@ -32,21 +40,41 @@ class DiaryCubit extends Cubit<DiaryState> {
emit((state as DiaryStateLoaded).copyWith(selectedMeal: selectedMeal));
}
fetchDiary([bool needLoading = false]) async {
fetchDiary([bool needLoading = false, int? diaryId]) async {
this.diaryId ??= diaryId;
if (needLoading) {
emit(const DiaryState.loading());
selectedMeal = 1;
}
try {
final diaryDay = await diaryRepository.getDiaryByDate('$selectedDay');
final DiaryDayModel diaryDay;
if (diaryId != null) {
diaryDay = await diaryRepository.getDiaryDay(diaryId);
} else {
final stringDate = selectedDay.toUtc().format('yyyy-MM-dd');
diaryDay = await diaryRepository.getDiaryByDate(stringDate);
}
ConsultantReviewModel? consultantReview;
if (diaryDay.chosenPlanId != null) {
consultantReview = await diaryRepository.getDiaryComments(planId: diaryDay.chosenPlanId!, diaryId: diaryDay.id);
}
final nutrition = await getNutrition(diaryDay.id);
final isDiaryFinished = diaryDay.typeOfDiary.diaryState == DiaryStateEnum.finished || diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayFinished;
final isDiaryCommented = diaryDay.typeOfDiary.diaryState == DiaryStateEnum.commented ||
diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayCommented ||
diaryDay.typeOfDiary.diaryState == DiaryStateEnum.reviewedByUser;
emit(
DiaryState.loaded(
diary: diaryDay,
nutrition: nutrition,
selectedDay: selectedDay,
selectedMeal: selectedMeal,
isConsultantView: this.diaryId != null,
consultantReview: consultantReview,
isDiaryFinished: isDiaryFinished,
isDiaryCommented: isDiaryCommented,
),
);
} catch (e, st) {
@@ -55,7 +83,11 @@ class DiaryCubit extends Cubit<DiaryState> {
}
}
finishDiaryDay({required int diaryId, required String wakeUp, required String retire, String? comment}) async {
finishDiaryDay({
required int diaryId,
required String wakeUp,
required String retire,
}) async {
await diaryRepository.finishDiaryDay(diaryId: diaryId, wakeUp: wakeUp, retire: retire, comment: comment);
await fetchDiary();
}
@@ -192,6 +224,6 @@ class DiaryCubit extends Cubit<DiaryState> {
}
fillComment(String comment) {
emit((state as DiaryStateLoaded).copyWith(diary: (state as DiaryStateLoaded).diary.copyWith(comment: comment)));
this.comment = comment;
}
}

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/features/diary/models/consultant_review_model.dart';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -19,6 +20,9 @@ class DiaryState with _$DiaryState {
required NutritionDataModel nutrition,
required DateTime selectedDay,
required int selectedMeal,
@Default(false) bool isConsultantView,
ConsultantReviewModel? consultantReview,
@Default(false) bool isDiaryFinished,
@Default(false) bool isDiaryCommented,
}) = DiaryStateLoaded;
}

View File

@@ -21,8 +21,15 @@ mixin _$DiaryState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)
required TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)
loaded,
}) =>
throw _privateConstructorUsedError;
@@ -31,8 +38,15 @@ mixin _$DiaryState {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult? Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
}) =>
throw _privateConstructorUsedError;
@@ -41,8 +55,15 @@ mixin _$DiaryState {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
required TResult orElse(),
}) =>
@@ -139,8 +160,15 @@ class _$DiaryStateImpl implements _DiaryState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)
required TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)
loaded,
}) {
return $default();
@@ -152,8 +180,15 @@ class _$DiaryStateImpl implements _DiaryState {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult? Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
}) {
return $default?.call();
@@ -165,8 +200,15 @@ class _$DiaryStateImpl implements _DiaryState {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
required TResult orElse(),
}) {
@@ -262,8 +304,15 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)
required TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)
loaded,
}) {
return loading();
@@ -275,8 +324,15 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult? Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
}) {
return loading?.call();
@@ -288,8 +344,15 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
required TResult orElse(),
}) {
@@ -414,8 +477,15 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)
required TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)
loaded,
}) {
return error(errorMessage);
@@ -427,8 +497,15 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult? Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
}) {
return error?.call(errorMessage);
@@ -440,8 +517,15 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
required TResult orElse(),
}) {
@@ -512,10 +596,15 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
{DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal});
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented});
$DiaryDayModelCopyWith<$Res> get diary;
$NutritionDataModelCopyWith<$Res> get nutrition;
$ConsultantReviewModelCopyWith<$Res>? get consultantReview;
}
/// @nodoc
@@ -535,6 +624,10 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
Object? nutrition = null,
Object? selectedDay = null,
Object? selectedMeal = null,
Object? isConsultantView = null,
Object? consultantReview = freezed,
Object? isDiaryFinished = null,
Object? isDiaryCommented = null,
}) {
return _then(_$DiaryStateLoadedImpl(
diary: null == diary
@@ -553,6 +646,22 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
? _value.selectedMeal
: selectedMeal // ignore: cast_nullable_to_non_nullable
as int,
isConsultantView: null == isConsultantView
? _value.isConsultantView
: isConsultantView // ignore: cast_nullable_to_non_nullable
as bool,
consultantReview: freezed == consultantReview
? _value.consultantReview
: consultantReview // ignore: cast_nullable_to_non_nullable
as ConsultantReviewModel?,
isDiaryFinished: null == isDiaryFinished
? _value.isDiaryFinished
: isDiaryFinished // ignore: cast_nullable_to_non_nullable
as bool,
isDiaryCommented: null == isDiaryCommented
? _value.isDiaryCommented
: isDiaryCommented // ignore: cast_nullable_to_non_nullable
as bool,
));
}
@@ -575,6 +684,21 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
return _then(_value.copyWith(nutrition: value));
});
}
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ConsultantReviewModelCopyWith<$Res>? get consultantReview {
if (_value.consultantReview == null) {
return null;
}
return $ConsultantReviewModelCopyWith<$Res>(_value.consultantReview!,
(value) {
return _then(_value.copyWith(consultantReview: value));
});
}
}
/// @nodoc
@@ -584,7 +708,11 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
{required this.diary,
required this.nutrition,
required this.selectedDay,
required this.selectedMeal});
required this.selectedMeal,
this.isConsultantView = false,
this.consultantReview,
this.isDiaryFinished = false,
this.isDiaryCommented = false});
@override
final DiaryDayModel diary;
@@ -594,10 +722,21 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
final DateTime selectedDay;
@override
final int selectedMeal;
@override
@JsonKey()
final bool isConsultantView;
@override
final ConsultantReviewModel? consultantReview;
@override
@JsonKey()
final bool isDiaryFinished;
@override
@JsonKey()
final bool isDiaryCommented;
@override
String toString() {
return 'DiaryState.loaded(diary: $diary, nutrition: $nutrition, selectedDay: $selectedDay, selectedMeal: $selectedMeal)';
return 'DiaryState.loaded(diary: $diary, nutrition: $nutrition, selectedDay: $selectedDay, selectedMeal: $selectedMeal, isConsultantView: $isConsultantView, consultantReview: $consultantReview, isDiaryFinished: $isDiaryFinished, isDiaryCommented: $isDiaryCommented)';
}
@override
@@ -611,12 +750,28 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
(identical(other.selectedDay, selectedDay) ||
other.selectedDay == selectedDay) &&
(identical(other.selectedMeal, selectedMeal) ||
other.selectedMeal == selectedMeal));
other.selectedMeal == selectedMeal) &&
(identical(other.isConsultantView, isConsultantView) ||
other.isConsultantView == isConsultantView) &&
(identical(other.consultantReview, consultantReview) ||
other.consultantReview == consultantReview) &&
(identical(other.isDiaryFinished, isDiaryFinished) ||
other.isDiaryFinished == isDiaryFinished) &&
(identical(other.isDiaryCommented, isDiaryCommented) ||
other.isDiaryCommented == isDiaryCommented));
}
@override
int get hashCode =>
Object.hash(runtimeType, diary, nutrition, selectedDay, selectedMeal);
int get hashCode => Object.hash(
runtimeType,
diary,
nutrition,
selectedDay,
selectedMeal,
isConsultantView,
consultantReview,
isDiaryFinished,
isDiaryCommented);
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.
@@ -633,11 +788,19 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)
required TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)
loaded,
}) {
return loaded(diary, nutrition, selectedDay, selectedMeal);
return loaded(diary, nutrition, selectedDay, selectedMeal, isConsultantView,
consultantReview, isDiaryFinished, isDiaryCommented);
}
@override
@@ -646,11 +809,19 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult? Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
}) {
return loaded?.call(diary, nutrition, selectedDay, selectedMeal);
return loaded?.call(diary, nutrition, selectedDay, selectedMeal,
isConsultantView, consultantReview, isDiaryFinished, isDiaryCommented);
}
@override
@@ -659,13 +830,28 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
DateTime selectedDay, int selectedMeal)?
TResult Function(
DiaryDayModel diary,
NutritionDataModel nutrition,
DateTime selectedDay,
int selectedMeal,
bool isConsultantView,
ConsultantReviewModel? consultantReview,
bool isDiaryFinished,
bool isDiaryCommented)?
loaded,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(diary, nutrition, selectedDay, selectedMeal);
return loaded(
diary,
nutrition,
selectedDay,
selectedMeal,
isConsultantView,
consultantReview,
isDiaryFinished,
isDiaryCommented);
}
return orElse();
}
@@ -713,12 +899,20 @@ abstract class DiaryStateLoaded implements DiaryState {
{required final DiaryDayModel diary,
required final NutritionDataModel nutrition,
required final DateTime selectedDay,
required final int selectedMeal}) = _$DiaryStateLoadedImpl;
required final int selectedMeal,
final bool isConsultantView,
final ConsultantReviewModel? consultantReview,
final bool isDiaryFinished,
final bool isDiaryCommented}) = _$DiaryStateLoadedImpl;
DiaryDayModel get diary;
NutritionDataModel get nutrition;
DateTime get selectedDay;
int get selectedMeal;
bool get isConsultantView;
ConsultantReviewModel? get consultantReview;
bool get isDiaryFinished;
bool get isDiaryCommented;
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.

View File

@@ -1,31 +1,62 @@
import 'dart:developer';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/widgets/data_error_widget.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/core/widgets/main_background_bouble.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/calendar_widget.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/calories_chart_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_for_consultant_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/day_comment_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/finish_day_button_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/wakeup_and_retire_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class DiaryScreen extends StatefulWidget {
class DiaryScreen extends StatelessWidget {
const DiaryScreen({super.key});
@override
State<DiaryScreen> createState() => _DiaryScreenState();
Widget build(BuildContext context) {
return const DiaryScreenContent();
}
}
class _DiaryScreenState extends State<DiaryScreen> {
class UserDiaryScreen extends StatelessWidget {
static const path = '/user-diary-screen';
static const name = 'userDiaryScreen';
const UserDiaryScreen({super.key, required this.diaryId});
final int diaryId;
@override
Widget build(BuildContext context) {
return BlocProvider<DiaryCubit>(
create: (BuildContext context) => sl<DiaryCubit>()..fetchDiary(true),
return DiaryScreenContent(diaryId: diaryId);
}
}
class DiaryScreenContent extends StatelessWidget {
const DiaryScreenContent({super.key, this.diaryId});
final int? diaryId;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return MultiBlocProvider(
providers: [
BlocProvider<DiaryCubit>(
create: (BuildContext context) => sl<DiaryCubit>()..fetchDiary(true, diaryId),
),
BlocProvider(
create: (context) => sl<ConsultantCommentsCubit>(),
),
],
child: BlocBuilder<DiaryCubit, DiaryState>(
builder: (BuildContext context, DiaryState state) {
if (state is DiaryStateLoaded) {
@@ -33,9 +64,10 @@ class _DiaryScreenState extends State<DiaryScreen> {
}
if (state is DiaryStateError) {
return Scaffold(
body: DataErrorWidget(onReload: () => context.read<DiaryCubit>().fetchDiary()),
body: DataErrorWidget(onReload: () => context.read<DiaryCubit>().fetchDiary(false, diaryId)),
);
}
return Scaffold(
backgroundColor: Colors.grey.shade200,
appBar: AppBar(
@@ -46,24 +78,79 @@ class _DiaryScreenState extends State<DiaryScreen> {
physics: const BouncingScrollPhysics(),
child: Column(
children: [
const CalendarWidget(),
if (diaryId == null) const CalendarWidget(),
if (state is DiaryStateLoading) const Loader(),
if (state is DiaryStateLoaded) WakeupAndRetireWidget(showRetire: state.diary.typeOfDiary.hasChosenPlan),
if (state is DiaryStateLoaded)
WakeupAndRetireWidget(
showRetire: state.diary.typeOfDiary.hasChosenPlan,
disable: state.isConsultantView || state.isDiaryFinished || state.isDiaryCommented,
),
const SizedBox(height: 12),
if (state is DiaryStateLoaded)
MealWidget(
showMood: state.diary.typeOfDiary.hasChosenPlan,
showAddButton: !state.isConsultantView && !state.isDiaryFinished && !state.isDiaryCommented,
),
if (state is DiaryStateLoaded) const CaloriesChartWidget(),
const SizedBox(height: 12),
if (state is DiaryStateLoaded && state.diary.typeOfDiary.hasChosenPlan) const CommentForConsultantWidget(),
if (state is DiaryStateLoaded && state.diary.closed == 0)
Builder(builder: (context) {
if (state is DiaryStateLoaded && state.diary.typeOfDiary.hasChosenPlan) {
if (state.diary.comment.isNotEmpty) {
return CommentForConsultantWidget(
comment: state.diary.comment,
);
}
if (state.isDiaryCommented || state.isDiaryFinished) {
return const SizedBox.shrink();
}
return const CommentForConsultantWidget();
}
return const SizedBox.shrink();
}),
if (state is DiaryStateLoaded && !state.isConsultantView && !state.isDiaryFinished && !state.isDiaryCommented)
Padding(
padding: const EdgeInsets.only(top: 12),
child: FinishDayButtonWidget(
diaryDay: state.diary,
),
),
if (state is DiaryStateLoaded && state.isConsultantView && !state.isDiaryCommented) ...[
const SizedBox(height: 16),
const MainBackgroundBouble(
padding: EdgeInsets.all(16),
child: DayCommentWidget(),
)
],
if (state is DiaryStateLoaded && state.consultantReview?.consultantComments.dayComment != null) ...[
const SizedBox(height: 12),
MainBackgroundBouble(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Text(
s.dayComment,
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CommentContainer(comment: state.consultantReview?.consultantComments.dayComment ?? ''),
],
),
),
const SizedBox(height: 28),
],
if (state is DiaryStateLoaded && state.isConsultantView && state.isDiaryFinished && !state.isDiaryCommented) ...[
const SizedBox(height: 16),
CustomOutlinedButton(
text: s.send,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () async {
await context.read<ConsultantCommentsCubit>().submitComments(state.diary.id);
},
),
const SizedBox(height: 16),
],
],
),
),

View File

@@ -0,0 +1,23 @@
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
class CommentContainer extends StatelessWidget {
const CommentContainer({super.key, required this.comment});
final String comment;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
width: double.infinity,
decoration: BoxDecoration(
color: appTheme.commentBg,
borderRadius: BorderRadius.circular(20),
),
child: Text(
comment,
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
),
);
}
}

View File

@@ -1,17 +1,26 @@
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CommentForConsultantWidget extends StatefulWidget {
const CommentForConsultantWidget({super.key});
const CommentForConsultantWidget({super.key, this.comment});
final String? comment;
@override
State<CommentForConsultantWidget> createState() => _CommentForConsultantWidgetState();
}
class _CommentForConsultantWidgetState extends State<CommentForConsultantWidget> {
final controller = TextEditingController();
@override
void initState() {
super.initState();
if (widget.comment != null) controller.text = widget.comment ?? '';
}
@override
Widget build(BuildContext context) {
return Material(
@@ -22,19 +31,22 @@ class _CommentForConsultantWidgetState extends State<CommentForConsultantWidget>
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
Text(
'Дополнительная информация для консультанта',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF323F4B), height: 1),
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CustomTextFormField(
controller: controller,
onChanged: (value) {
EasyDebounce.debounce('client-typing', const Duration(seconds: 3), () => context.read<DiaryCubit>().fillComment(value));
EasyDebounce.debounce('client-typing', const Duration(milliseconds: 500), () => context.read<DiaryCubit>().fillComment(value));
},
hintText: 'Укажите дополнительную информацию',
minLines: 4,
maxLines: 4,
readOnly: widget.comment != null,
),
],
),

View File

@@ -0,0 +1,45 @@
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_state.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class DayCommentWidget extends StatelessWidget {
const DayCommentWidget({super.key});
@override
Widget build(BuildContext context) {
final s = S.of(context);
return BlocBuilder<ConsultantCommentsCubit, ConsultantCommentsState>(
builder: (context, state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
s.dayCommentTitle,
textAlign: TextAlign.center,
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CustomTextFormField(
onChanged: (value) {
EasyDebounce.debounce('client-typing', const Duration(milliseconds: 500), () => context.read<ConsultantCommentsCubit>().setComment(value));
},
hasError: state.dayCommentNeedsToBeFilled,
hintText: s.typeDayComment,
minLines: 4,
maxLines: 4,
readOnly: false,
),
if (state.dayCommentNeedsToBeFilled) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Минимум 3 символа')],
],
);
},
);
}
}

View File

@@ -17,12 +17,10 @@ class _FinishDayButtonWidgetState extends State<FinishDayButtonWidget> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap:
() => context.read<DiaryCubit>().finishDiaryDay(
onTap: () => context.read<DiaryCubit>().finishDiaryDay(
diaryId: widget.diaryDay.id,
wakeUp: widget.diaryDay.wakeup.toString(),
retire: widget.diaryDay.retire.toString(),
comment: widget.diaryDay.comment.isEmpty ? null : widget.diaryDay.comment,
),
borderRadius: BorderRadius.circular(20),
child: Ink(

View File

@@ -0,0 +1,74 @@
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_state.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MealCommentWidget extends StatefulWidget {
const MealCommentWidget({super.key, required this.selectedMeal});
final int selectedMeal;
@override
State<MealCommentWidget> createState() => _MealCommentWidgetState();
}
class _MealCommentWidgetState extends State<MealCommentWidget> {
final controller = TextEditingController();
@override
void didUpdateWidget(MealCommentWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.selectedMeal != oldWidget.selectedMeal) {
final state = context.read<ConsultantCommentsCubit>().state;
controller.text = state.commentsModel.mealsComments[widget.selectedMeal.toString()]?.comment ?? '';
}
}
@override
Widget build(BuildContext context) {
final s = S.of(context);
return BlocBuilder<ConsultantCommentsCubit, ConsultantCommentsState>(
builder: (context, state) {
final bool hasError;
if (state.commentsModel.mealsComments[widget.selectedMeal.toString()] != null &&
state.commentsModel.mealsComments[widget.selectedMeal.toString()]!.comment.length < 3) {
hasError = true;
} else {
hasError = false;
}
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'${s.commentForMeal} ${widget.selectedMeal}',
textAlign: TextAlign.center,
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CustomTextFormField(
controller: controller,
hasError: hasError,
onChanged: (value) {
EasyDebounce.debounce(
'client-typing',
const Duration(milliseconds: 500),
() => context.read<ConsultantCommentsCubit>().setMealComment(mealNumber: widget.selectedMeal, comment: value),
);
},
hintText: s.typeMealComment,
minLines: 4,
maxLines: 4,
readOnly: false,
),
if (hasError) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Минимум 3 символа')],
],
);
},
);
}
}

View File

@@ -1,15 +1,24 @@
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/add_product_button_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_button_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_comment_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/mood_rating_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/photo_gallery_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/products_list_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/satiety_rating_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/time_of_meal_picker_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MealWidget extends StatefulWidget {
const MealWidget({super.key, required this.showMood});
const MealWidget({super.key, required this.showMood, required this.showAddButton});
final bool showMood;
final bool showAddButton;
@override
State<MealWidget> createState() => _MealWidgetState();
}
@@ -17,6 +26,7 @@ class MealWidget extends StatefulWidget {
class _MealWidgetState extends State<MealWidget> {
@override
Widget build(BuildContext context) {
final s = S.of(context);
return Material(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
@@ -48,8 +58,10 @@ class _MealWidgetState extends State<MealWidget> {
const TimeOfMealPickerWidget(),
const SizedBox(height: 12),
const ProductsListWidget(),
const SizedBox(height: 12),
const AddProductButtonWidget(),
if (widget.showAddButton) ...[
const SizedBox(height: 12),
const AddProductButtonWidget(),
],
const SizedBox(height: 12),
const PhotoGalleryWidget(),
const SizedBox(height: 12),
@@ -57,7 +69,35 @@ class _MealWidgetState extends State<MealWidget> {
if (widget.showMood) ...[
const SizedBox(height: 12),
const MoodRatingWidget(),
]
],
BlocBuilder<DiaryCubit, DiaryState>(
builder: (context, state) {
if (state is DiaryStateLoaded && state.isConsultantView && !state.isDiaryCommented) {
return MealCommentWidget(selectedMeal: state.selectedMeal);
}
return const SizedBox.shrink();
},
),
BlocBuilder<DiaryCubit, DiaryState>(
builder: (context, state) {
if (state is DiaryStateLoaded) {
final mealsComments = state.consultantReview?.consultantComments.mealsComments;
if (mealsComments != null && (state.selectedMeal - 1 < mealsComments.length)) {
return Column(
children: [
Text(
'${s.mealComment} ${state.selectedMeal}',
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CommentContainer(comment: mealsComments[state.selectedMeal - 1].comment),
],
);
}
}
return const SizedBox.shrink();
},
)
],
),
),

View File

@@ -32,9 +32,10 @@ class _MoodRatingWidgetState extends State<MoodRatingWidget> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Ваше настроение после приёма пищи',
style: TextStyle(
Text(
state.isConsultantView ? 'Настроение пользователя после приема пищи' : 'Ваше настроение после приёма пищи',
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16,
),
),
@@ -47,6 +48,7 @@ class _MoodRatingWidgetState extends State<MoodRatingWidget> {
width: 32,
),
RatingBar.builder(
ignoreGestures: state.isConsultantView || state.isDiaryFinished || state.isDiaryCommented,
initialRating: state.diary.meals[selectedIndex].mood.toDouble() + 1,
itemCount: 6,
itemSize: MediaQuery.of(context).size.width / 6 - (124 / 6),

View File

@@ -90,7 +90,7 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
builder: (context, state) {
if (state is DiaryStateLoaded) {
int mealIndex = state.selectedMeal - 1;
if (state.diary.meals[mealIndex].photos.isEmpty) {
if (state.diary.meals[mealIndex].photos.isEmpty && !state.isConsultantView && !state.isDiaryFinished && !state.isDiaryCommented) {
return GestureDetector(
onTap: () => showImagePicker(state.diary),
child: SvgPicture.asset(
@@ -99,6 +99,9 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
),
);
} else {
if (state.diary.meals[mealIndex].photos.isEmpty) {
return const SizedBox.shrink();
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -112,30 +115,31 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
imageUrl: '$baseUrl/storage/${state.diary.meals[mealIndex].photos[currentSelectedPhotoIndex].path}',
),
),
Padding(
padding: const EdgeInsets.all(12),
child: IconButton.filled(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
elevation: 0,
),
onPressed: () async {
await diaryCubit.deletePhoto(
photo: state.diary.meals[mealIndex].photos[currentSelectedPhotoIndex],
diaryId: state.diary.id,
);
setState(() {
if (currentSelectedPhotoIndex == state.diary.meals[mealIndex].photos.length - 1 && currentSelectedPhotoIndex != 0) {
currentSelectedPhotoIndex = state.diary.meals[mealIndex].photos.length - 2;
}
});
},
icon: const Icon(
Icons.close_rounded,
color: Colors.grey,
if (!state.isConsultantView && !state.isDiaryFinished && !state.isDiaryCommented)
Padding(
padding: const EdgeInsets.all(12),
child: IconButton.filled(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
elevation: 0,
),
onPressed: () async {
await diaryCubit.deletePhoto(
photo: state.diary.meals[mealIndex].photos[currentSelectedPhotoIndex],
diaryId: state.diary.id,
);
setState(() {
if (currentSelectedPhotoIndex == state.diary.meals[mealIndex].photos.length - 1 && currentSelectedPhotoIndex != 0) {
currentSelectedPhotoIndex = state.diary.meals[mealIndex].photos.length - 2;
}
});
},
icon: const Icon(
Icons.close_rounded,
color: Colors.grey,
),
),
),
),
],
),
const SizedBox(height: 8),
@@ -147,7 +151,7 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
for (int i = 0; i < state.diary.meals[mealIndex].photos.length + 1; i++) ...[
if (i == state.diary.meals[mealIndex].photos.length)
if (i == state.diary.meals[mealIndex].photos.length && !state.isConsultantView && !state.isDiaryFinished && !state.isDiaryCommented)
Padding(
padding: const EdgeInsets.only(left: 8),
child: InkWell(

View File

@@ -0,0 +1,86 @@
import 'package:collection/collection.dart';
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/diary/models/consultant_comment_model.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/consultant_comments_cubit/consultant_comments_state.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class PortionCommentWidget extends StatefulWidget {
const PortionCommentWidget({super.key, required this.enabled, required this.portionId, this.comment});
final bool enabled;
final int portionId;
final String? comment;
@override
State<PortionCommentWidget> createState() => _PortionCommentWidgetState();
}
class _PortionCommentWidgetState extends State<PortionCommentWidget> {
final controller = TextEditingController();
@override
void didUpdateWidget(PortionCommentWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.portionId != oldWidget.portionId) {
final state = context.read<ConsultantCommentsCubit>().state;
controller.text = state.commentsModel.portions.firstWhereOrNull((portion) => portion.id == widget.portionId)?.comment ?? '';
}
}
@override
void initState() {
super.initState();
final state = context.read<ConsultantCommentsCubit>().state;
controller.text = state.commentsModel.portions.firstWhereOrNull((portion) => portion.id == widget.portionId)?.comment ?? '';
}
@override
Widget build(BuildContext context) {
final s = S.of(context);
if (widget.enabled) {
return BlocBuilder<ConsultantCommentsCubit, ConsultantCommentsState>(
builder: (context, state) {
final bool hasError;
if (state.commentsModel.portions.firstWhereOrNull((elem) => elem.id == widget.portionId) != null &&
state.commentsModel.portions.firstWhereOrNull((elem) => elem.id == widget.portionId)!.comment.length < 3) {
hasError = true;
} else {
hasError = false;
}
return Column(
children: [
CustomTextFormField(
controller: controller,
hintText: s.typePortionComment,
hasError: hasError,
onChanged: (value) {
EasyDebounce.debounce(
'client-typing',
const Duration(milliseconds: 500),
() {
final hasPortionComment = state.commentsModel.portions.any((portion) => portion.id == widget.portionId);
if (hasPortionComment) {
final portion = state.commentsModel.portions.firstWhere((portion) => portion.id == widget.portionId);
context.read<ConsultantCommentsCubit>().updatePortionComment(portion.copyWith(comment: value));
return;
}
context.read<ConsultantCommentsCubit>().addPortionComment(PortionCommentModel(id: widget.portionId, comment: value));
},
);
},
),
if (hasError) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Минимум 3 символа')],
],
);
},
);
}
if (widget.comment != null) {
return CommentContainer(comment: widget.comment ?? '');
}
return const SizedBox.shrink();
}
}

View File

@@ -1,9 +1,13 @@
import 'package:collection/collection.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/consultations/models/consultation_model.dart';
import 'package:eatvio_app/features/diary/models/consultant_review_model.dart';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/add_product_modal.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/portion_comment_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
@@ -24,7 +28,7 @@ class _ProductWidgetState extends State<ProductWidget> {
late final DiaryCubit diaryCubit;
late String portionName;
late bool isEaten;
bool showCommentWidget = false;
@override
void initState() {
super.initState();
@@ -55,6 +59,17 @@ class _ProductWidgetState extends State<ProductWidget> {
return BlocBuilder<DiaryCubit, DiaryState>(
builder: (context, state) {
if (state is DiaryStateLoaded) {
final isDiaryCommented = state.diary.typeOfDiary.diaryState == DiaryStateEnum.commented ||
state.diary.typeOfDiary.diaryState == DiaryStateEnum.lastDayCommented ||
state.diary.typeOfDiary.diaryState == DiaryStateEnum.reviewedByUser;
final isDiaryFinished =
state.diary.typeOfDiary.diaryState == DiaryStateEnum.finished || state.diary.typeOfDiary.diaryState == DiaryStateEnum.lastDayFinished;
final canEditPortion = !state.isConsultantView && !isDiaryCommented && !isDiaryFinished;
final consultantComments = state.consultantReview?.consultantComments;
PortionComment? portionComment;
if (consultantComments != null) {
portionComment = consultantComments.portionsComments.firstWhereOrNull((elem) => elem.portionId == widget.portion.id);
}
if (widget.portion.portionState == PortionState.eatenDeleted) {
return DottedBorder(
dashPattern: const [6, 6],
@@ -84,50 +99,74 @@ class _ProductWidgetState extends State<ProductWidget> {
),
);
} else {
return ListTile(
onTap: () => updateProductInMeal(state, widget.portion),
trailing: const Icon(Icons.more_vert_rounded),
leading: widget.portion.fromDiet
? Transform.scale(
scale: 1.2,
child: Checkbox(
value: isEaten,
onChanged: (value) {
setState(() {
isEaten = value!;
});
if (isEaten) {
diaryCubit.markEaten(
diaryId: state.diary.id,
mealId: state.selectedMeal,
portionId: widget.portion.id,
);
} else {
diaryCubit.unmarkEaten(
diaryId: state.diary.id,
mealId: state.selectedMeal,
portionId: widget.portion.id,
);
}
},
activeColor: appTheme.blueA400,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
side: const BorderSide(
color: Color(0xFF809CB9),
),
),
)
: null,
horizontalTitleGap: 0,
contentPadding: widget.portion.fromDiet ? const EdgeInsets.only(right: 24, left: 4) : null,
title: Text(widget.portion.productName),
subtitle: Text('${widget.portion.quantity} ${widget.portion.portion == 'gr' ? 'гр' : 'шт'}'),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
tileColor: const Color(0xFFF6FAFF),
Widget? trailing;
if (state.isConsultantView && !isDiaryCommented) {
trailing = GestureDetector(
onTap: () {
setState(() {
showCommentWidget = !showCommentWidget;
});
},
child: SvgPicture.asset('assets/icons/edit.svg'));
} else if (!isDiaryCommented) {
trailing = const Icon(Icons.more_vert_rounded);
}
return Column(
children: [
ListTile(
onTap: canEditPortion ? () => updateProductInMeal(state, widget.portion) : null,
trailing: trailing,
leading: widget.portion.fromDiet
? Transform.scale(
scale: 1.2,
child: Checkbox(
value: isEaten,
onChanged: (value) {
setState(() {
isEaten = value!;
});
if (isEaten) {
diaryCubit.markEaten(
diaryId: state.diary.id,
mealId: state.selectedMeal,
portionId: widget.portion.id,
);
} else {
diaryCubit.unmarkEaten(
diaryId: state.diary.id,
mealId: state.selectedMeal,
portionId: widget.portion.id,
);
}
},
activeColor: appTheme.blueA400,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
side: const BorderSide(
color: Color(0xFF809CB9),
),
),
)
: null,
horizontalTitleGap: 0,
contentPadding: widget.portion.fromDiet ? const EdgeInsets.only(right: 24, left: 4) : null,
title: Text(widget.portion.productName),
subtitle: Text('${widget.portion.quantity} ${widget.portion.portion == 'gr' ? 'гр' : 'шт'}'),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
tileColor: const Color(0xFFF6FAFF),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: PortionCommentWidget(
enabled: showCommentWidget,
portionId: widget.portion.id,
comment: portionComment?.comment,
),
)
],
);
}
}

View File

@@ -15,7 +15,7 @@ class _ProductsListWidgetState extends State<ProductsListWidget> {
@override
Widget build(BuildContext context) {
return BlocBuilder<DiaryCubit, DiaryState>(
builder: (BuildContext context, DiaryState state) {
builder: (BuildContext context, DiaryState state) {
if (state is DiaryStateLoaded) {
int mealIndex = state.selectedMeal - 1;
return Column(

View File

@@ -32,9 +32,10 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Ваша сытость после приёма пищи',
style: TextStyle(
Text(
state.isConsultantView ? 'Сытость пользователя после приема пищи' : 'Ваша сытость после приёма пищи',
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16,
),
),
@@ -47,6 +48,7 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
width: 32,
),
RatingBar.builder(
ignoreGestures: state.isConsultantView || state.isDiaryFinished || state.isDiaryCommented,
initialRating: state.diary.meals[selectedIndex].satiety.toDouble() + 1,
itemCount: 6,
itemSize: MediaQuery.of(context).size.width / 6 - (124 / 6),
@@ -172,6 +174,7 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
}
},
onRatingUpdate: (value) {
if (state.isConsultantView) return;
setState(() {
currentSelectedRating[selectedIndex] = value;
});

View File

@@ -69,6 +69,7 @@ class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
),
),
),
const SizedBox(height: 30)
],
),
),
@@ -97,7 +98,7 @@ class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
),
),
InkWell(
onTap: () => showTimePicker(state.diary.id),
onTap: state.isConsultantView || state.isDiaryFinished || state.isDiaryCommented ? null : () => showTimePicker(state.diary.id),
borderRadius: BorderRadius.circular(100),
child: Ink(
height: 32,

View File

@@ -8,8 +8,9 @@ import 'package:flutter_svg/flutter_svg.dart';
import '../../../../core/theme/theme_helper.dart';
class WakeupAndRetireWidget extends StatefulWidget {
const WakeupAndRetireWidget({super.key, required this.showRetire});
const WakeupAndRetireWidget({super.key, required this.showRetire, this.disable = false});
final bool showRetire;
final bool disable;
@override
State<WakeupAndRetireWidget> createState() => _WakeupAndRetireWidgetState();
}
@@ -82,6 +83,7 @@ class _WakeupAndRetireWidgetState extends State<WakeupAndRetireWidget> {
),
),
),
const SizedBox(height: 30)
],
),
),
@@ -125,7 +127,7 @@ class _WakeupAndRetireWidgetState extends State<WakeupAndRetireWidget> {
),
const SizedBox(height: 8),
InkWell(
onTap: () => showTimePicker(state.diary.id, true),
onTap: widget.disable ? null : () => showTimePicker(state.diary.id, true),
borderRadius: BorderRadius.circular(100),
child: Ink(
height: 32,
@@ -185,7 +187,7 @@ class _WakeupAndRetireWidgetState extends State<WakeupAndRetireWidget> {
),
const SizedBox(height: 8),
InkWell(
onTap: () => showTimePicker(state.diary.id, false),
onTap: widget.disable ? null : () => showTimePicker(state.diary.id, false),
borderRadius: BorderRadius.circular(100),
child: Ink(
height: 32,