forked from eatvio/eatvio_app
91 lines
3.3 KiB
Dart
91 lines
3.3 KiB
Dart
import 'package:eatvio_app/core/routing/route_constants.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_divider.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/generated/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class ChosenDietWidget extends StatelessWidget {
|
|
const ChosenDietWidget({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<DiaryCubit, DiaryState>(
|
|
builder: (context, state) {
|
|
if (state is DiaryStateLoaded) {
|
|
if (state.diary.typeOfDiary.hasChosenDiet) {
|
|
return ChosenDietWidgetContent(
|
|
currentDietDay: state.diary.dayOfChosenDiet ?? 0,
|
|
dietName: state.diary.diet?.name ?? '',
|
|
dietDuration: state.diary.diet?.duration ?? 0,
|
|
dietId: state.diary.diet?.id ?? 0,
|
|
);
|
|
}
|
|
}
|
|
if (state is DiaryStateLoadedTomorrowWithDiet) {
|
|
if (state.diary.typeOfDiary.hasChosenDiet) {
|
|
return Column(
|
|
children: [
|
|
const CustomDivider(),
|
|
const SizedBox(height: 16),
|
|
ChosenDietWidgetContent(
|
|
currentDietDay: state.diary.dayOfChosenDiet ?? 0,
|
|
dietName: state.diary.diet?.name ?? '',
|
|
dietDuration: state.diary.diet?.duration ?? 0,
|
|
dietId: state.diary.diet?.id ?? 0,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
return const SizedBox.shrink();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChosenDietWidgetContent extends StatelessWidget {
|
|
const ChosenDietWidgetContent({super.key, required this.currentDietDay, required this.dietName, required this.dietDuration, required this.dietId});
|
|
final int currentDietDay;
|
|
final String dietName;
|
|
final int dietDuration;
|
|
final int dietId;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.sizeOf(context);
|
|
final s = S.of(context);
|
|
return GestureDetector(
|
|
onTap: () {
|
|
GoRouter.of(context).push(RouteConstants.aboutDietScreen, extra: {'id': dietId, 'navigateToComments': false});
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: size.width * 0.4,
|
|
child: Text(
|
|
dietName,
|
|
style: TextStyles.textLMedium.copyWith(color: appTheme.black, decoration: TextDecoration.underline),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Container(
|
|
decoration: BoxDecoration(color: appTheme.dividerColor, borderRadius: BorderRadius.circular(12)),
|
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
|
child: Text('${s.day} $currentDietDay из $dietDuration', style: TextStyles.textMSemibold.copyWith(color: appTheme.gray)),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|