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(),
|
builder: (context, state) => FeedScreen(),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/diary-screen',
|
path: '/diary-screen',
|
||||||
name: 'diaryScreen',
|
name: 'diaryScreen',
|
||||||
builder: (context, state) => DiaryScreen(),
|
builder: (context, state) {
|
||||||
),
|
if (state.extra != null)
|
||||||
|
return DiaryScreen(diaryID: state.extra as String);
|
||||||
|
else
|
||||||
|
return DiaryScreen(diaryID: '0');
|
||||||
|
}),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/chat-select-screen',
|
path: '/chat-select-screen',
|
||||||
name: 'chatSelectScreen',
|
name: 'chatSelectScreen',
|
||||||
@@ -96,7 +100,8 @@ class AppRouter {
|
|||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/blog-post-screen',
|
path: '/blog-post-screen',
|
||||||
name: 'blogPostScreen',
|
name: 'blogPostScreen',
|
||||||
builder: (context, state) => BlogPostScreen(blogPostID: state.extra as String),
|
builder: (context, state) =>
|
||||||
|
BlogPostScreen(blogPostID: state.extra as String),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/blog-post-edit-screen',
|
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
|
// 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_cubit.dart';
|
||||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
||||||
import 'package:eatvio_app/core/app_export.dart';
|
import 'package:eatvio_app/core/app_export.dart';
|
||||||
import 'package:go_router/go_router.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/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||||
@@ -54,7 +53,7 @@ class CalendarScreen extends StatelessWidget {
|
|||||||
toolbarHeight: 0,
|
toolbarHeight: 0,
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
),
|
),
|
||||||
backgroundColor: Color.fromARGB(255, 240, 242, 245),
|
backgroundColor: Colors.white,
|
||||||
resizeToAvoidBottomInset: true,
|
resizeToAvoidBottomInset: true,
|
||||||
body: SizedBox(
|
body: SizedBox(
|
||||||
width: double.maxFinite,
|
width: double.maxFinite,
|
||||||
@@ -83,82 +82,247 @@ class CalendarScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildCalendarBody(BuildContext context, CalendarStateLoaded state) {
|
_buildCalendarBody(BuildContext context, CalendarStateLoaded state) {
|
||||||
return Container(
|
return ListView.separated(
|
||||||
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
|
padding: EdgeInsets.all(8),
|
||||||
padding: EdgeInsets.symmetric(
|
shrinkWrap: true,
|
||||||
horizontal: 24.h,
|
physics: NeverScrollableScrollPhysics(),
|
||||||
vertical: 12.v,
|
separatorBuilder: (context, index) {
|
||||||
),
|
return SizedBox(
|
||||||
decoration: BoxDecoration(
|
height: 2.v,
|
||||||
color: Colors.white,
|
);
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
},
|
||||||
boxShadow: [
|
itemCount: state.calendarList.length,
|
||||||
BoxShadow(
|
itemBuilder: (context, index) {
|
||||||
color: Colors.grey.withOpacity(0.5),
|
Map<String, dynamic> diary = {};
|
||||||
spreadRadius: 2,
|
if (state.calendarList[index].diary is List<dynamic>) {
|
||||||
blurRadius: 5,
|
diary['status'] = 'Скоро';
|
||||||
offset: Offset(0, 3),
|
return InkWell(
|
||||||
),
|
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||||
],
|
child: Ink(
|
||||||
),
|
padding: EdgeInsets.all(8),
|
||||||
child: TableCalendar(
|
decoration: BoxDecoration(
|
||||||
locale: 'ru_RU',
|
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||||
firstDay: DateTime.utc(2010, 10, 16),
|
color: getBackgroundColor(diary['state']),
|
||||||
lastDay: DateTime.utc(2030, 3, 14),
|
),
|
||||||
focusedDay: DateTime.now(),
|
child: Row(
|
||||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
calendarBuilders: CalendarBuilders(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
selectedBuilder: (context, day, focusedDay) =>
|
children: [
|
||||||
_buildCellDate(context, day, focusedDay: focusedDay, state),
|
Expanded(
|
||||||
defaultBuilder: (context, day, focusedDay) =>
|
child: Column(
|
||||||
_buildCellDate(context, day, state),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
todayBuilder: (context, day, focusedDay) =>
|
children: [
|
||||||
_buildCellDate(context, day, state),
|
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(
|
String _getStateText(String state) {
|
||||||
BuildContext context, DateTime day, CalendarStateLoaded state,
|
switch (state) {
|
||||||
{DateTime? focusedDay}) {
|
case 'finished':
|
||||||
final String dayString = day.toIso8601String().split('T').first;
|
return 'Готово';
|
||||||
final List<CalendarModel> calendarModels = state.calendarList;
|
case 'started':
|
||||||
|
return 'В процессе';
|
||||||
// Находим первую модель, соответствующую дате
|
default:
|
||||||
final CalendarModel model = calendarModels.firstWhere(
|
return ''; // Возвращаем пустую строку, если состояние не распознано
|
||||||
(model) => model.date == dayString,
|
}
|
||||||
orElse: () => CalendarModel(date: dayString, diary: {}));
|
}
|
||||||
|
|
||||||
Color? bgclr; // Объявляем переменную bgclr здесь
|
String formatDate(String dateString) {
|
||||||
|
// Преобразуем строку в объект DateTime
|
||||||
final Map<String, dynamic> diary = model.diary as Map<String, dynamic>;
|
DateTime dateTime = DateTime.parse(dateString);
|
||||||
if (model.diary is Map<String, dynamic>) {
|
|
||||||
if (diary['state'] == "started") {
|
// Форматируем дату
|
||||||
bgclr = Colors.grey;
|
String formattedDate = DateFormat('d MMMM', 'ru_RU').format(dateTime);
|
||||||
} else if (diary['state'] == "finished") {
|
|
||||||
bgclr = Colors.green;
|
// Возвращаем результат в нужном формате
|
||||||
} else {
|
return '$formattedDate';
|
||||||
bgclr = Colors.white;
|
}
|
||||||
}
|
|
||||||
} else {
|
Color getBackgroundColor(String? status) {
|
||||||
bgclr = Colors.white; // Значение по умолчанию, если diary не является Map
|
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> {
|
class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||||
final DiaryRepository diaryRepository;
|
final DiaryRepository diaryRepository;
|
||||||
|
|
||||||
DiaryBloc({required this.diaryRepository}) : super(const DiaryState.loading()) {
|
DiaryBloc({required this.diaryRepository})
|
||||||
|
: super(const DiaryState.loading()) {
|
||||||
on<LoadDiary>(loadDiary);
|
on<LoadDiary>(loadDiary);
|
||||||
|
on<LoadDiaryById>(loadDiaryById);
|
||||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||||
on<ChangeMealTime>(_changeMealTime); // пользовательяет времяа пиши
|
on<ChangeMealTime>(_changeMealTime); // пользовательяет времяа пиши
|
||||||
@@ -53,15 +55,119 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
|||||||
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
|
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
|
||||||
final Meal currentMeal = diary.meals[0];
|
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> chartData =
|
||||||
final Map<String, dynamic> dailyNutritionIntake = chartData['dailyNutritionIntake']!;
|
await diaryRepository.getChartData(diaryID ?? 45);
|
||||||
final Map<String, dynamic> dailyNutritionRecommendations = chartData['dailyNutritionRecommendation']!;
|
final Map<String, dynamic> dailyNutritionIntake =
|
||||||
final double ccal = dailyNutritionIntake['energy']! / dailyNutritionRecommendations['energy']! * 50;
|
chartData['dailyNutritionIntake']!;
|
||||||
final double proteins = dailyNutritionIntake['proteins']! / dailyNutritionRecommendations['proteins']! * 50;
|
final Map<String, dynamic> dailyNutritionRecommendations =
|
||||||
final double fats = dailyNutritionIntake['fats']! / dailyNutritionRecommendations['fats']! * 50;
|
chartData['dailyNutritionRecommendation']!;
|
||||||
final double carbs = dailyNutritionIntake['carbohydrates']! / dailyNutritionRecommendations['carbohydrates']! * 50;
|
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) {
|
Color getColor(double value) {
|
||||||
if (value >= 99.1) {
|
if (value >= 99.1) {
|
||||||
@@ -163,9 +269,11 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
|||||||
) async {
|
) async {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
var currentState = state as 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 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(
|
await diaryRepository.changeWakeup(
|
||||||
currentState.diary.id,
|
currentState.diary.id,
|
||||||
wakeupString,
|
wakeupString,
|
||||||
@@ -180,9 +288,11 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
|||||||
) async {
|
) async {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
var currentState = state as 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 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(
|
await diaryRepository.changeRetire(
|
||||||
currentState.diary.id,
|
currentState.diary.id,
|
||||||
retireString,
|
retireString,
|
||||||
@@ -208,7 +318,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
|||||||
) async {
|
) async {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
final currentState = state as 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(
|
DiaryStateLoaded updatedState = currentState.copyWith(
|
||||||
currentMeal: meal,
|
currentMeal: meal,
|
||||||
portions: meal.portions,
|
portions: meal.portions,
|
||||||
@@ -227,10 +338,12 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
|||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
var currentState = state as 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(
|
var updatedState = currentState.copyWith(
|
||||||
product_nameController: TextEditingController(text: event.input),
|
product_nameController: TextEditingController(text: event.input),
|
||||||
autocompleteList: productNutritionalValues['product_nutritional_value'] ?? [],
|
autocompleteList:
|
||||||
|
productNutritionalValues['product_nutritional_value'] ?? [],
|
||||||
);
|
);
|
||||||
if (event.input.length > 3) {
|
if (event.input.length > 3) {
|
||||||
updatedState = updatedState.copyWith(moderationExpanded: true);
|
updatedState = updatedState.copyWith(moderationExpanded: true);
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ class LoadDiary extends DiaryEvent {
|
|||||||
List<Object?> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LoadDiaryById extends DiaryEvent {
|
||||||
|
LoadDiaryById(
|
||||||
|
this.id,
|
||||||
|
);
|
||||||
|
final String? id;
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
class ChangeSatiety extends DiaryEvent {
|
class ChangeSatiety extends DiaryEvent {
|
||||||
ChangeSatiety(
|
ChangeSatiety(
|
||||||
this.selectedElement,
|
this.selectedElement,
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ part 'diary_state.freezed.dart';
|
|||||||
abstract class DiaryState with _$DiaryState {
|
abstract class DiaryState with _$DiaryState {
|
||||||
const factory DiaryState() = _DiaryState;
|
const factory DiaryState() = _DiaryState;
|
||||||
|
|
||||||
const factory DiaryState.loading() = DiaryStateLoading;
|
const factory DiaryState.loading({
|
||||||
|
int? id,
|
||||||
|
}) = DiaryStateLoading;
|
||||||
|
|
||||||
const factory DiaryState.loaded({
|
const factory DiaryState.loaded({
|
||||||
required DiaryModel diary,
|
required DiaryModel diary,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ mixin _$DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>(
|
TResult when<TResult extends Object?>(
|
||||||
TResult Function() $default, {
|
TResult Function() $default, {
|
||||||
required TResult Function() loading,
|
required TResult Function(int? id) loading,
|
||||||
required TResult Function(
|
required TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -56,7 +56,7 @@ mixin _$DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>(
|
TResult? whenOrNull<TResult extends Object?>(
|
||||||
TResult? Function()? $default, {
|
TResult? Function()? $default, {
|
||||||
TResult? Function()? loading,
|
TResult? Function(int? id)? loading,
|
||||||
TResult? Function(
|
TResult? Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -93,7 +93,7 @@ mixin _$DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>(
|
TResult maybeWhen<TResult extends Object?>(
|
||||||
TResult Function()? $default, {
|
TResult Function()? $default, {
|
||||||
TResult Function()? loading,
|
TResult Function(int? id)? loading,
|
||||||
TResult Function(
|
TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -212,7 +212,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>(
|
TResult when<TResult extends Object?>(
|
||||||
TResult Function() $default, {
|
TResult Function() $default, {
|
||||||
required TResult Function() loading,
|
required TResult Function(int? id) loading,
|
||||||
required TResult Function(
|
required TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -252,7 +252,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>(
|
TResult? whenOrNull<TResult extends Object?>(
|
||||||
TResult? Function()? $default, {
|
TResult? Function()? $default, {
|
||||||
TResult? Function()? loading,
|
TResult? Function(int? id)? loading,
|
||||||
TResult? Function(
|
TResult? Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -292,7 +292,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>(
|
TResult maybeWhen<TResult extends Object?>(
|
||||||
TResult Function()? $default, {
|
TResult Function()? $default, {
|
||||||
TResult Function()? loading,
|
TResult Function(int? id)? loading,
|
||||||
TResult Function(
|
TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -379,6 +379,8 @@ abstract class _$$DiaryStateLoadingImplCopyWith<$Res> {
|
|||||||
factory _$$DiaryStateLoadingImplCopyWith(_$DiaryStateLoadingImpl value,
|
factory _$$DiaryStateLoadingImplCopyWith(_$DiaryStateLoadingImpl value,
|
||||||
$Res Function(_$DiaryStateLoadingImpl) then) =
|
$Res Function(_$DiaryStateLoadingImpl) then) =
|
||||||
__$$DiaryStateLoadingImplCopyWithImpl<$Res>;
|
__$$DiaryStateLoadingImplCopyWithImpl<$Res>;
|
||||||
|
@useResult
|
||||||
|
$Res call({int? id});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@@ -388,32 +390,57 @@ class __$$DiaryStateLoadingImplCopyWithImpl<$Res>
|
|||||||
__$$DiaryStateLoadingImplCopyWithImpl(_$DiaryStateLoadingImpl _value,
|
__$$DiaryStateLoadingImplCopyWithImpl(_$DiaryStateLoadingImpl _value,
|
||||||
$Res Function(_$DiaryStateLoadingImpl) _then)
|
$Res Function(_$DiaryStateLoadingImpl) _then)
|
||||||
: super(_value, _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
|
/// @nodoc
|
||||||
|
|
||||||
class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||||
const _$DiaryStateLoadingImpl();
|
const _$DiaryStateLoadingImpl({this.id});
|
||||||
|
|
||||||
|
@override
|
||||||
|
final int? id;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'DiaryState.loading()';
|
return 'DiaryState.loading(id: $id)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return identical(this, 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
|
@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
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>(
|
TResult when<TResult extends Object?>(
|
||||||
TResult Function() $default, {
|
TResult Function() $default, {
|
||||||
required TResult Function() loading,
|
required TResult Function(int? id) loading,
|
||||||
required TResult Function(
|
required TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -446,14 +473,14 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
|||||||
loaded,
|
loaded,
|
||||||
required TResult Function(String errorMessage) error,
|
required TResult Function(String errorMessage) error,
|
||||||
}) {
|
}) {
|
||||||
return loading();
|
return loading(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>(
|
TResult? whenOrNull<TResult extends Object?>(
|
||||||
TResult? Function()? $default, {
|
TResult? Function()? $default, {
|
||||||
TResult? Function()? loading,
|
TResult? Function(int? id)? loading,
|
||||||
TResult? Function(
|
TResult? Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -486,14 +513,14 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
|||||||
loaded,
|
loaded,
|
||||||
TResult? Function(String errorMessage)? error,
|
TResult? Function(String errorMessage)? error,
|
||||||
}) {
|
}) {
|
||||||
return loading?.call();
|
return loading?.call(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>(
|
TResult maybeWhen<TResult extends Object?>(
|
||||||
TResult Function()? $default, {
|
TResult Function()? $default, {
|
||||||
TResult Function()? loading,
|
TResult Function(int? id)? loading,
|
||||||
TResult Function(
|
TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -528,7 +555,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
|||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) {
|
}) {
|
||||||
if (loading != null) {
|
if (loading != null) {
|
||||||
return loading();
|
return loading(id);
|
||||||
}
|
}
|
||||||
return orElse();
|
return orElse();
|
||||||
}
|
}
|
||||||
@@ -572,7 +599,12 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class DiaryStateLoading implements DiaryState {
|
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
|
/// @nodoc
|
||||||
@@ -1050,7 +1082,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>(
|
TResult when<TResult extends Object?>(
|
||||||
TResult Function() $default, {
|
TResult Function() $default, {
|
||||||
required TResult Function() loading,
|
required TResult Function(int? id) loading,
|
||||||
required TResult Function(
|
required TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -1118,7 +1150,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>(
|
TResult? whenOrNull<TResult extends Object?>(
|
||||||
TResult? Function()? $default, {
|
TResult? Function()? $default, {
|
||||||
TResult? Function()? loading,
|
TResult? Function(int? id)? loading,
|
||||||
TResult? Function(
|
TResult? Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -1186,7 +1218,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>(
|
TResult maybeWhen<TResult extends Object?>(
|
||||||
TResult Function()? $default, {
|
TResult Function()? $default, {
|
||||||
TResult Function()? loading,
|
TResult Function(int? id)? loading,
|
||||||
TResult Function(
|
TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -1423,7 +1455,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>(
|
TResult when<TResult extends Object?>(
|
||||||
TResult Function() $default, {
|
TResult Function() $default, {
|
||||||
required TResult Function() loading,
|
required TResult Function(int? id) loading,
|
||||||
required TResult Function(
|
required TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -1463,7 +1495,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>(
|
TResult? whenOrNull<TResult extends Object?>(
|
||||||
TResult? Function()? $default, {
|
TResult? Function()? $default, {
|
||||||
TResult? Function()? loading,
|
TResult? Function(int? id)? loading,
|
||||||
TResult? Function(
|
TResult? Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
@@ -1503,7 +1535,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
|||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>(
|
TResult maybeWhen<TResult extends Object?>(
|
||||||
TResult Function()? $default, {
|
TResult Function()? $default, {
|
||||||
TResult Function()? loading,
|
TResult Function(int? id)? loading,
|
||||||
TResult Function(
|
TResult Function(
|
||||||
DiaryModel diary,
|
DiaryModel diary,
|
||||||
String? diaryDate,
|
String? diaryDate,
|
||||||
|
|||||||
@@ -23,8 +23,17 @@ import 'package:syncfusion_flutter_charts/charts.dart';
|
|||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class DiaryScreen extends StatelessWidget {
|
class DiaryScreen extends StatelessWidget {
|
||||||
DiaryScreen({Key? key}) : super(key: key);
|
final String? diaryID;
|
||||||
|
|
||||||
|
const DiaryScreen({
|
||||||
|
this.diaryID,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (diaryID != "0") {
|
||||||
|
context.read<DiaryBloc>().add(LoadDiaryById(diaryID));
|
||||||
|
}
|
||||||
return BlocBuilder<DiaryBloc, DiaryState>(
|
return BlocBuilder<DiaryBloc, DiaryState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
@@ -141,7 +150,6 @@ class DiaryScreen extends StatelessWidget {
|
|||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
widthFactor: 0.5,
|
widthFactor: 0.5,
|
||||||
child: SfCircularChart(
|
child: SfCircularChart(
|
||||||
legend: Legend(isVisible: false),
|
|
||||||
series: <CircularSeries>[
|
series: <CircularSeries>[
|
||||||
RadialBarSeries<NutritionData, String>(
|
RadialBarSeries<NutritionData, String>(
|
||||||
dataSource: state.chartData,
|
dataSource: state.chartData,
|
||||||
@@ -153,30 +161,29 @@ class DiaryScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
SizedBox(height: 16.0),
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text('Калории'),
|
|
||||||
Text('Белки'),
|
|
||||||
Text('Жиры'),
|
|
||||||
Text('Углеводы'),
|
Text('Углеводы'),
|
||||||
|
Text('Жиры'),
|
||||||
|
Text('Белки'),
|
||||||
|
Text('Калории'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${state.chartData![0].nutrition.toStringAsFixed(1)}'), // Калории
|
'${state.chartData![3].nutrition.toStringAsFixed(0)}%'), // Калории
|
||||||
Text(
|
Text(
|
||||||
'${state.chartData![1].nutrition.toStringAsFixed(1)}'), // Белки
|
'${state.chartData![2].nutrition.toStringAsFixed(0)}%'), // Белки
|
||||||
Text(
|
Text(
|
||||||
'${state.chartData![2].nutrition.toStringAsFixed(1)}'), // Жиры
|
'${state.chartData![1].nutrition.toStringAsFixed(0)}%'), // Жиры
|
||||||
Text(
|
Text(
|
||||||
'${state.chartData![3].nutrition.toStringAsFixed(1)}'), // Углеводы
|
'${state.chartData![0].nutrition.toStringAsFixed(0)}% '), // Углеводы
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user