refactor(diary): API methods all refactored and new nutrition charty finished

This commit is contained in:
2024-07-24 17:12:28 +03:00
parent 7535e82422
commit 0671c5d072
11 changed files with 568 additions and 443 deletions

View File

@@ -7,20 +7,20 @@ import 'package:eatvio_app/features/diary/models/portion.dart';
import 'package:eatvio_app/features/diary/models/product.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_bloc.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart';
import 'package:eatvio_app/widgets/custom_edit_drop_down.dart';
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/widgets/custom_scale_element.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:image_picker/image_picker.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
// ignore: must_be_immutable
class DiaryScreen extends StatelessWidget {
@@ -89,7 +89,7 @@ class DiaryScreen extends StatelessWidget {
_buildMeal(context, state),
SizedBox(height: 20.v),
_buildMood(context, state),
SizedBox(height: 30.v),
SizedBox(height: 20.v),
_buildNutritionChart(context, state),
SizedBox(height: 30.v),
_buildComment(context, state),
@@ -109,6 +109,39 @@ class DiaryScreen extends StatelessWidget {
);
}
_buildNutritionChart(BuildContext context, DiaryStateLoaded 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: SfCircularChart(
title: ChartTitle(text: 'График КБЖУ'),
legend: Legend(isVisible: true),
series: <CircularSeries>[
RadialBarSeries<NutritionData, String>(
dataSource: state.chartData,
xValueMapper: (NutritionData data, _) => data.category,
yValueMapper: (NutritionData data, _) => data.nutrition,
pointColorMapper: (NutritionData data, _) => data.color,
)
],
));
}
_buildEndDay(BuildContext context) {
return CustomOutlinedButton(
text: "Закончить день",
@@ -122,7 +155,6 @@ class DiaryScreen extends StatelessWidget {
color: Colors.transparent,
),
onPressed: onFinishDayPressed(context),
// Установите прозрачный фон
);
}
@@ -217,8 +249,6 @@ class DiaryScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
// Показывайте прелоадер, если загрузка активна
Padding(
padding: EdgeInsets.only(
left: 7.h,
@@ -461,13 +491,6 @@ class DiaryScreen extends StatelessWidget {
.map((portion) => _buildProduct(context, portion))
.toList(),
SizedBox(height: 30.v),
/*...state.photos != null
? state.photos!.isEmpty
? [Text('Фото пока нет')]
: state.photos!
.map((photo) => _buildPhoto(context, photo))
.toList()
: [Text('Фото нет')],*/
_buildCarousel(context, state),
SizedBox(height: 20.v),
_buildAddPhoto(context, state),
@@ -600,7 +623,6 @@ class DiaryScreen extends StatelessWidget {
BuildContext dialogContext,
) {
return () {
// Call function to send moderation with the entered values
context.read<DiaryBloc>().add(
SendModeration(
name: name,
@@ -610,7 +632,7 @@ class DiaryScreen extends StatelessWidget {
carbohydratesOn100gr: carbohydratesOn100gr,
),
);
Navigator.of(dialogContext).pop(); // Dismiss the dialog
Navigator.of(dialogContext).pop();
};
}
@@ -670,8 +692,7 @@ class DiaryScreen extends StatelessWidget {
return CarouselSlider(
options: CarouselOptions(height: 340.0),
items: state.currentMeal.photos.map<Widget>((photo) {
return _buildPhoto(
context, photo); // Assuming photos are stored as strings
return _buildPhoto(context, photo);
}).toList(),
);
}
@@ -777,7 +798,7 @@ class DiaryScreen extends StatelessWidget {
};
}
_buildNutritionChart(BuildContext context, DiaryStateLoaded state) {
/*_buildNutritionChart(BuildContext context, DiaryStateLoaded state) {
final List<int> recommendedValues = state
.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
final List<int> consumedValues = state.consumedChartValues; //
@@ -996,7 +1017,7 @@ class DiaryScreen extends StatelessWidget {
],
),
);
}
}*/
/// Section Widget
_buildComment(BuildContext context, DiaryStateLoaded state) {