forked from eatvio/eatvio_app
168 lines
7.4 KiB
Dart
168 lines
7.4 KiB
Dart
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 StatelessWidget {
|
|
const DiaryScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const DiaryScreenContent();
|
|
}
|
|
}
|
|
|
|
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 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) {
|
|
log(state.diary.id.toString());
|
|
}
|
|
if (state is DiaryStateError) {
|
|
return Scaffold(
|
|
body: DataErrorWidget(onReload: () => context.read<DiaryCubit>().fetchDiary(false, diaryId)),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey.shade200,
|
|
appBar: AppBar(
|
|
toolbarHeight: 0,
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Column(
|
|
children: [
|
|
if (diaryId == null) const CalendarWidget(),
|
|
if (state is DiaryStateLoading) ...[
|
|
const SizedBox(
|
|
height: 60,
|
|
),
|
|
const Loader()
|
|
],
|
|
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),
|
|
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),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|