forked from eatvio/eatvio_app
Merge branch 'main' into feature/feed
This commit is contained in:
@@ -70,10 +70,14 @@ class AppRouter {
|
||||
builder: (context, state) => FeedScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/diary-screen',
|
||||
name: 'diaryScreen',
|
||||
builder: (context, state) => DiaryScreen(),
|
||||
),
|
||||
path: '/diary-screen',
|
||||
name: 'diaryScreen',
|
||||
builder: (context, state) {
|
||||
if (state.extra != null)
|
||||
return DiaryScreen(diaryID: state.extra as String);
|
||||
else
|
||||
return DiaryScreen(diaryID: '0');
|
||||
}),
|
||||
GoRoute(
|
||||
path: '/chat-select-screen',
|
||||
name: 'chatSelectScreen',
|
||||
@@ -96,7 +100,8 @@ class AppRouter {
|
||||
GoRoute(
|
||||
path: '/blog-post-screen',
|
||||
name: 'blogPostScreen',
|
||||
builder: (context, state) => BlogPostScreen(blogPostID: state.extra as String),
|
||||
builder: (context, state) =>
|
||||
BlogPostScreen(blogPostID: state.extra as String),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/blog-post-edit-screen',
|
||||
|
||||
18
lib/features/calendar/models/calendar_entry_model.dart
Normal file
18
lib/features/calendar/models/calendar_entry_model.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
/// This class is used in the [userprofile_item_widget] screen.
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
class CalendarEntryModel {
|
||||
String? date;
|
||||
String? status;
|
||||
String id;
|
||||
|
||||
CalendarEntryModel({
|
||||
this.date,
|
||||
this.status,
|
||||
required this.id,
|
||||
}) {
|
||||
date = date;
|
||||
status = status;
|
||||
id = id;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
import 'package:eatvio_app/features/calendar/models/calendar_model.dart';
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_cubit.dart';
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
@@ -54,7 +53,7 @@ class CalendarScreen extends StatelessWidget {
|
||||
toolbarHeight: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
backgroundColor: Color.fromARGB(255, 240, 242, 245),
|
||||
backgroundColor: Colors.white,
|
||||
resizeToAvoidBottomInset: true,
|
||||
body: SizedBox(
|
||||
width: double.maxFinite,
|
||||
@@ -83,82 +82,247 @@ class CalendarScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
_buildCalendarBody(BuildContext context, CalendarStateLoaded state) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 24.h,
|
||||
vertical: 12.v,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 5,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TableCalendar(
|
||||
locale: 'ru_RU',
|
||||
firstDay: DateTime.utc(2010, 10, 16),
|
||||
lastDay: DateTime.utc(2030, 3, 14),
|
||||
focusedDay: DateTime.now(),
|
||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
selectedBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, focusedDay: focusedDay, state),
|
||||
defaultBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, state),
|
||||
todayBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, state),
|
||||
),
|
||||
),
|
||||
return ListView.separated(
|
||||
padding: EdgeInsets.all(8),
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(
|
||||
height: 2.v,
|
||||
);
|
||||
},
|
||||
itemCount: state.calendarList.length,
|
||||
itemBuilder: (context, index) {
|
||||
Map<String, dynamic> diary = {};
|
||||
if (state.calendarList[index].diary is List<dynamic>) {
|
||||
diary['status'] = 'Скоро';
|
||||
return InkWell(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
child: Ink(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
color: getBackgroundColor(diary['state']),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
formatDate(state.calendarList[index].date),
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: 2.v),
|
||||
if (diary['state'] != null)
|
||||
Row(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: diary['state'] == 'finished'
|
||||
? Color.fromRGBO(1, 154, 62, 1)
|
||||
: Color.fromRGBO(154, 74, 1, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
_getStateText(diary['state'] ?? ''),
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
if (diary['state'] == 'started')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Заполнить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
if (diary['state'] == 'finished')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Изменить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
]),
|
||||
if (state.calendarList[index].diary is List<dynamic>)
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(108, 117, 125, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Cкоро',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
diary = state.calendarList[index].diary as Map<String, dynamic>;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
onTap: () => GoRouter.of(context).go(
|
||||
'/diary-screen',
|
||||
extra: diary['id'].toString(),
|
||||
),
|
||||
child: Ink(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
color: getBackgroundColor(diary['state']),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
formatDate(state.calendarList[index].date),
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: 2.v),
|
||||
if (diary['state'] != null)
|
||||
Row(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: diary['state'] == 'finished'
|
||||
? Color.fromRGBO(1, 154, 62, 1)
|
||||
: Color.fromRGBO(154, 74, 1, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
_getStateText(diary['state'] ?? ''),
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
if (diary['state'] == 'started')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Заполнить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
if (diary['state'] == 'finished')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Изменить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
]),
|
||||
if (state.calendarList[index].diary is List<dynamic>)
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(108, 117, 125, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Cкоро',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildCellDate(
|
||||
BuildContext context, DateTime day, CalendarStateLoaded state,
|
||||
{DateTime? focusedDay}) {
|
||||
final String dayString = day.toIso8601String().split('T').first;
|
||||
final List<CalendarModel> calendarModels = state.calendarList;
|
||||
|
||||
// Находим первую модель, соответствующую дате
|
||||
final CalendarModel model = calendarModels.firstWhere(
|
||||
(model) => model.date == dayString,
|
||||
orElse: () => CalendarModel(date: dayString, diary: {}));
|
||||
|
||||
Color? bgclr; // Объявляем переменную bgclr здесь
|
||||
|
||||
final Map<String, dynamic> diary = model.diary as Map<String, dynamic>;
|
||||
if (model.diary is Map<String, dynamic>) {
|
||||
if (diary['state'] == "started") {
|
||||
bgclr = Colors.grey;
|
||||
} else if (diary['state'] == "finished") {
|
||||
bgclr = Colors.green;
|
||||
} else {
|
||||
bgclr = Colors.white;
|
||||
}
|
||||
} else {
|
||||
bgclr = Colors.white; // Значение по умолчанию, если diary не является Map
|
||||
String _getStateText(String state) {
|
||||
switch (state) {
|
||||
case 'finished':
|
||||
return 'Готово';
|
||||
case 'started':
|
||||
return 'В процессе';
|
||||
default:
|
||||
return ''; // Возвращаем пустую строку, если состояние не распознано
|
||||
}
|
||||
}
|
||||
|
||||
String formatDate(String dateString) {
|
||||
// Преобразуем строку в объект DateTime
|
||||
DateTime dateTime = DateTime.parse(dateString);
|
||||
|
||||
// Форматируем дату
|
||||
String formattedDate = DateFormat('d MMMM', 'ru_RU').format(dateTime);
|
||||
|
||||
// Возвращаем результат в нужном формате
|
||||
return '$formattedDate';
|
||||
}
|
||||
|
||||
Color getBackgroundColor(String? status) {
|
||||
switch (status) {
|
||||
case 'finished':
|
||||
return Color.fromRGBO(1, 154, 62, .1);
|
||||
case 'started':
|
||||
return Color.fromRGBO(154, 74, 1, .1);
|
||||
default:
|
||||
return Color.fromRGBO(126, 136, 151, .1);
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'diaryScreen',
|
||||
extra: diary['id'],
|
||||
),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
shape: (day == focusedDay) ? BoxShape.circle : BoxShape.rectangle,
|
||||
color: bgclr,
|
||||
borderRadius: (day == focusedDay) ? null : BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(day.day.toString(), style: TextStyle(color: Colors.black)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ part 'diary_event.dart';
|
||||
class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
final DiaryRepository diaryRepository;
|
||||
|
||||
DiaryBloc({required this.diaryRepository}) : super(const DiaryState.loading()) {
|
||||
DiaryBloc({required this.diaryRepository})
|
||||
: super(const DiaryState.loading()) {
|
||||
on<LoadDiary>(loadDiary);
|
||||
on<LoadDiaryById>(loadDiaryById);
|
||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
on<ChangeMealTime>(_changeMealTime); // пользовательяет времяа пиши
|
||||
@@ -53,15 +55,119 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
|
||||
final Meal currentMeal = diary.meals[0];
|
||||
|
||||
List<SelectionPopupModel> portionList = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")];
|
||||
List<SelectionPopupModel> portionList = [
|
||||
SelectionPopupModel(title: "gr"),
|
||||
SelectionPopupModel(title: "pcs")
|
||||
];
|
||||
|
||||
final Map<String, dynamic> chartData = await diaryRepository.getChartData(diaryID ?? 45);
|
||||
final Map<String, dynamic> dailyNutritionIntake = chartData['dailyNutritionIntake']!;
|
||||
final Map<String, dynamic> dailyNutritionRecommendations = chartData['dailyNutritionRecommendation']!;
|
||||
final double ccal = dailyNutritionIntake['energy']! / dailyNutritionRecommendations['energy']! * 50;
|
||||
final double proteins = dailyNutritionIntake['proteins']! / dailyNutritionRecommendations['proteins']! * 50;
|
||||
final double fats = dailyNutritionIntake['fats']! / dailyNutritionRecommendations['fats']! * 50;
|
||||
final double carbs = dailyNutritionIntake['carbohydrates']! / dailyNutritionRecommendations['carbohydrates']! * 50;
|
||||
final Map<String, dynamic> chartData =
|
||||
await diaryRepository.getChartData(diaryID ?? 45);
|
||||
final Map<String, dynamic> dailyNutritionIntake =
|
||||
chartData['dailyNutritionIntake']!;
|
||||
final Map<String, dynamic> dailyNutritionRecommendations =
|
||||
chartData['dailyNutritionRecommendation']!;
|
||||
final double ccal = dailyNutritionIntake['energy']! /
|
||||
dailyNutritionRecommendations['energy']! *
|
||||
50;
|
||||
final double proteins = dailyNutritionIntake['proteins']! /
|
||||
dailyNutritionRecommendations['proteins']! *
|
||||
50;
|
||||
final double fats = dailyNutritionIntake['fats']! /
|
||||
dailyNutritionRecommendations['fats']! *
|
||||
50;
|
||||
final double carbs = dailyNutritionIntake['carbohydrates']! /
|
||||
dailyNutritionRecommendations['carbohydrates']! *
|
||||
50;
|
||||
|
||||
Color getColor(double value) {
|
||||
if (value >= 99.1) {
|
||||
return Colors.red;
|
||||
} else {
|
||||
return Colors.blue;
|
||||
}
|
||||
}
|
||||
|
||||
final List<NutritionData> chartDataCounted = [
|
||||
NutritionData('Калории', ccal, getColor(ccal)),
|
||||
NutritionData('Белки', proteins, getColor(proteins)),
|
||||
NutritionData('Жиры', fats, getColor(fats)),
|
||||
NutritionData('Углеводы', carbs, getColor(carbs)),
|
||||
];
|
||||
|
||||
List<SelectionPopupModel> mealList = [
|
||||
SelectionPopupModel(title: "Прием пищи 1", id: 1),
|
||||
SelectionPopupModel(title: "Прием пищи 2", id: 2),
|
||||
SelectionPopupModel(title: "Прием пищи 3", id: 3),
|
||||
SelectionPopupModel(title: "Прием пищи 4", id: 4),
|
||||
SelectionPopupModel(title: "Прием пищи 5", id: 5),
|
||||
SelectionPopupModel(title: "Прием пищи 6", id: 6),
|
||||
];
|
||||
|
||||
emit(DiaryState.loaded(
|
||||
diary: diary,
|
||||
currentMeal: currentMeal,
|
||||
portions: currentMeal.portions,
|
||||
portionList: portionList,
|
||||
portionController: portionList[0],
|
||||
mealList: mealList,
|
||||
chartData: chartDataCounted,
|
||||
selectedMood: currentMeal.mood,
|
||||
selectedSatiety: currentMeal.satiety,
|
||||
wakeupController: TimeOfDay.now(),
|
||||
retireController: TimeOfDay.now(),
|
||||
commentController: TextEditingController(),
|
||||
product_nameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
proteinsController: TextEditingController(),
|
||||
carbsController: TextEditingController(),
|
||||
wakeupExpanded: false,
|
||||
moderationExpanded: false,
|
||||
moodExpanded: false,
|
||||
isLoading: false,
|
||||
isAdded: false,
|
||||
autocompleteList: [],
|
||||
recommendedChartValues: [1, 1, 1, 1],
|
||||
consumedChartValues: [1, 1, 1, 1]));
|
||||
} catch (e) {
|
||||
emit(DiaryState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
loadDiaryById(
|
||||
LoadDiaryById event,
|
||||
Emitter<DiaryState> emit,
|
||||
) async {
|
||||
emit(const DiaryState.loading());
|
||||
try {
|
||||
final int diaryID = int.parse(event.id ?? "0");
|
||||
final DiaryModel diary = await diaryRepository.getDiary(diaryID);
|
||||
final Meal currentMeal = diary.meals[0];
|
||||
|
||||
List<SelectionPopupModel> portionList = [
|
||||
SelectionPopupModel(title: "gr"),
|
||||
SelectionPopupModel(title: "pcs")
|
||||
];
|
||||
|
||||
final Map<String, dynamic> chartData =
|
||||
await diaryRepository.getChartData(diaryID);
|
||||
final Map<String, dynamic> dailyNutritionIntake =
|
||||
chartData['dailyNutritionIntake']!;
|
||||
final Map<String, dynamic> dailyNutritionRecommendations =
|
||||
chartData['dailyNutritionRecommendation']!;
|
||||
final double ccal = dailyNutritionIntake['energy']! /
|
||||
dailyNutritionRecommendations['energy']! *
|
||||
50;
|
||||
final double proteins = dailyNutritionIntake['proteins']! /
|
||||
dailyNutritionRecommendations['proteins']! *
|
||||
50;
|
||||
final double fats = dailyNutritionIntake['fats']! /
|
||||
dailyNutritionRecommendations['fats']! *
|
||||
50;
|
||||
final double carbs = dailyNutritionIntake['carbohydrates']! /
|
||||
dailyNutritionRecommendations['carbohydrates']! *
|
||||
50;
|
||||
|
||||
Color getColor(double value) {
|
||||
if (value >= 99.1) {
|
||||
@@ -163,9 +269,11 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
var updatedState = currentState.copyWith(wakeupController: event.selectedTime);
|
||||
var updatedState =
|
||||
currentState.copyWith(wakeupController: event.selectedTime);
|
||||
final DateFormat formatter = DateFormat('HH:mm');
|
||||
final String wakeupString = formatter.format(DateTime(2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute));
|
||||
final String wakeupString = formatter.format(DateTime(
|
||||
2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute));
|
||||
await diaryRepository.changeWakeup(
|
||||
currentState.diary.id,
|
||||
wakeupString,
|
||||
@@ -180,9 +288,11 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
var updatedState = currentState.copyWith(retireController: event.selectedTime);
|
||||
var updatedState =
|
||||
currentState.copyWith(retireController: event.selectedTime);
|
||||
final DateFormat formatter = DateFormat('HH:mm');
|
||||
final String retireString = formatter.format(DateTime(2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute));
|
||||
final String retireString = formatter.format(DateTime(
|
||||
2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute));
|
||||
await diaryRepository.changeRetire(
|
||||
currentState.diary.id,
|
||||
retireString,
|
||||
@@ -208,7 +318,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
final currentState = state as DiaryStateLoaded;
|
||||
final Meal meal = currentState.diary.meals.firstWhere((meal) => meal.type == event.value.id);
|
||||
final Meal meal = currentState.diary.meals
|
||||
.firstWhere((meal) => meal.type == event.value.id);
|
||||
DiaryStateLoaded updatedState = currentState.copyWith(
|
||||
currentMeal: meal,
|
||||
portions: meal.portions,
|
||||
@@ -227,10 +338,12 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
final Map<String, List<Product>> productNutritionalValues = await diaryRepository.inputProduct(event.input);
|
||||
final Map<String, List<Product>> productNutritionalValues =
|
||||
await diaryRepository.inputProduct(event.input);
|
||||
var updatedState = currentState.copyWith(
|
||||
product_nameController: TextEditingController(text: event.input),
|
||||
autocompleteList: productNutritionalValues['product_nutritional_value'] ?? [],
|
||||
autocompleteList:
|
||||
productNutritionalValues['product_nutritional_value'] ?? [],
|
||||
);
|
||||
if (event.input.length > 3) {
|
||||
updatedState = updatedState.copyWith(moderationExpanded: true);
|
||||
|
||||
@@ -15,6 +15,15 @@ class LoadDiary extends DiaryEvent {
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoadDiaryById extends DiaryEvent {
|
||||
LoadDiaryById(
|
||||
this.id,
|
||||
);
|
||||
final String? id;
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ChangeSatiety extends DiaryEvent {
|
||||
ChangeSatiety(
|
||||
this.selectedElement,
|
||||
|
||||
@@ -13,7 +13,9 @@ part 'diary_state.freezed.dart';
|
||||
abstract class DiaryState with _$DiaryState {
|
||||
const factory DiaryState() = _DiaryState;
|
||||
|
||||
const factory DiaryState.loading() = DiaryStateLoading;
|
||||
const factory DiaryState.loading({
|
||||
int? id,
|
||||
}) = DiaryStateLoading;
|
||||
|
||||
const factory DiaryState.loaded({
|
||||
required DiaryModel diary,
|
||||
|
||||
@@ -19,7 +19,7 @@ mixin _$DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(int? id) loading,
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -56,7 +56,7 @@ mixin _$DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(int? id)? loading,
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -93,7 +93,7 @@ mixin _$DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(int? id)? loading,
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -212,7 +212,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(int? id) loading,
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -252,7 +252,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(int? id)? loading,
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -292,7 +292,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(int? id)? loading,
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -379,6 +379,8 @@ abstract class _$$DiaryStateLoadingImplCopyWith<$Res> {
|
||||
factory _$$DiaryStateLoadingImplCopyWith(_$DiaryStateLoadingImpl value,
|
||||
$Res Function(_$DiaryStateLoadingImpl) then) =
|
||||
__$$DiaryStateLoadingImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({int? id});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -388,32 +390,57 @@ class __$$DiaryStateLoadingImplCopyWithImpl<$Res>
|
||||
__$$DiaryStateLoadingImplCopyWithImpl(_$DiaryStateLoadingImpl _value,
|
||||
$Res Function(_$DiaryStateLoadingImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
}) {
|
||||
return _then(_$DiaryStateLoadingImpl(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
const _$DiaryStateLoadingImpl();
|
||||
const _$DiaryStateLoadingImpl({this.id});
|
||||
|
||||
@override
|
||||
final int? id;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DiaryState.loading()';
|
||||
return 'DiaryState.loading(id: $id)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$DiaryStateLoadingImpl);
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$DiaryStateLoadingImpl &&
|
||||
(identical(other.id, id) || other.id == id));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
int get hashCode => Object.hash(runtimeType, id);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$DiaryStateLoadingImplCopyWith<_$DiaryStateLoadingImpl> get copyWith =>
|
||||
__$$DiaryStateLoadingImplCopyWithImpl<_$DiaryStateLoadingImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(int? id) loading,
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -446,14 +473,14 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
return loading(id);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(int? id)? loading,
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -486,14 +513,14 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
return loading?.call(id);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(int? id)? loading,
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -528,7 +555,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
return loading();
|
||||
return loading(id);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
@@ -572,7 +599,12 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
}
|
||||
|
||||
abstract class DiaryStateLoading implements DiaryState {
|
||||
const factory DiaryStateLoading() = _$DiaryStateLoadingImpl;
|
||||
const factory DiaryStateLoading({final int? id}) = _$DiaryStateLoadingImpl;
|
||||
|
||||
int? get id;
|
||||
@JsonKey(ignore: true)
|
||||
_$$DiaryStateLoadingImplCopyWith<_$DiaryStateLoadingImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -1050,7 +1082,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(int? id) loading,
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -1118,7 +1150,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(int? id)? loading,
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -1186,7 +1218,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(int? id)? loading,
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -1423,7 +1455,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(int? id) loading,
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -1463,7 +1495,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(int? id)? loading,
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
@@ -1503,7 +1535,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(int? id)? loading,
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
|
||||
@@ -23,8 +23,17 @@ import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class DiaryScreen extends StatelessWidget {
|
||||
DiaryScreen({Key? key}) : super(key: key);
|
||||
final String? diaryID;
|
||||
|
||||
const DiaryScreen({
|
||||
this.diaryID,
|
||||
super.key,
|
||||
});
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
if (diaryID != "0") {
|
||||
context.read<DiaryBloc>().add(LoadDiaryById(diaryID));
|
||||
}
|
||||
return BlocBuilder<DiaryBloc, DiaryState>(
|
||||
builder: (context, state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
@@ -141,7 +150,6 @@ class DiaryScreen extends StatelessWidget {
|
||||
alignment: Alignment.centerRight,
|
||||
widthFactor: 0.5,
|
||||
child: SfCircularChart(
|
||||
legend: Legend(isVisible: false),
|
||||
series: <CircularSeries>[
|
||||
RadialBarSeries<NutritionData, String>(
|
||||
dataSource: state.chartData,
|
||||
@@ -153,30 +161,29 @@ class DiaryScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
)),
|
||||
SizedBox(height: 16.0),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Калории'),
|
||||
Text('Белки'),
|
||||
Text('Жиры'),
|
||||
Text('Углеводы'),
|
||||
Text('Жиры'),
|
||||
Text('Белки'),
|
||||
Text('Калории'),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${state.chartData![0].nutrition.toStringAsFixed(1)}'), // Калории
|
||||
'${state.chartData![3].nutrition.toStringAsFixed(0)}%'), // Калории
|
||||
Text(
|
||||
'${state.chartData![1].nutrition.toStringAsFixed(1)}'), // Белки
|
||||
'${state.chartData![2].nutrition.toStringAsFixed(0)}%'), // Белки
|
||||
Text(
|
||||
'${state.chartData![2].nutrition.toStringAsFixed(1)}'), // Жиры
|
||||
'${state.chartData![1].nutrition.toStringAsFixed(0)}%'), // Жиры
|
||||
Text(
|
||||
'${state.chartData![3].nutrition.toStringAsFixed(1)}'), // Углеводы
|
||||
'${state.chartData![0].nutrition.toStringAsFixed(0)}% '), // Углеводы
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user