forked from eatvio/eatvio_app
feat(diary): add finish day button and glossary moderation request
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/nutrition_model.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/finish_day_button_widget.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/satiety_rating_widget.dart';
|
||||
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
@@ -33,6 +34,7 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
DateTime _focusedDay = DateTime.now();
|
||||
DateTime? _selectedDay = DateTime.now();
|
||||
late final DateTime? today;
|
||||
int currentSelectedMealNumber = 1;
|
||||
GlossaryModel? selectedGlossary;
|
||||
final productNameController = TextEditingController();
|
||||
@@ -40,6 +42,13 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
int currentSelectedPhotoIndex = 0;
|
||||
String time = "${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}";
|
||||
DateTime _time = DateTime.now();
|
||||
bool enableQuantity = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
today = _selectedDay;
|
||||
}
|
||||
|
||||
_showDatePicker() {
|
||||
showModalBottomSheet<void>(
|
||||
@@ -65,12 +74,6 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
useSafeArea: false,
|
||||
context: context,
|
||||
builder: (context) => GlossaryModerationRequestModalWidget(),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
@@ -128,6 +131,11 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
state.currentSelectedSatietyRating,
|
||||
),
|
||||
if (state is DiaryStateLoaded) _chart(state.nutrition),
|
||||
if (state is DiaryStateLoaded && state.diary.closed == 0 && _selectedDay == today)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: FinishDayButtonWidget(diaryDay: state.diary),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
@@ -504,17 +512,27 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
_chartData('Калории',
|
||||
'${nutrition.dailyNutritionIntake.energy.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.energy.toStringAsFixed(0)} ккал'),
|
||||
_chartData(
|
||||
'Калории',
|
||||
'${nutrition.dailyNutritionIntake.energy.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.energy.toStringAsFixed(0)} ккал',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_chartData('Белки',
|
||||
'${nutrition.dailyNutritionIntake.proteins.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.proteins.toStringAsFixed(0)} грамм'),
|
||||
_chartData(
|
||||
'Белки',
|
||||
'${nutrition.dailyNutritionIntake.proteins.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.proteins.toStringAsFixed(
|
||||
0,
|
||||
)} грамм',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_chartData('Жиры',
|
||||
'${nutrition.dailyNutritionIntake.fats.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.fats.toStringAsFixed(0)} грамм'),
|
||||
_chartData(
|
||||
'Жиры',
|
||||
'${nutrition.dailyNutritionIntake.fats.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.fats.toStringAsFixed(0)} грамм',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_chartData('Углеводы',
|
||||
'${nutrition.dailyNutritionIntake.carbohydrates.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.carbohydrates.toStringAsFixed(0)} грамм'),
|
||||
_chartData(
|
||||
'Углеводы',
|
||||
'${nutrition.dailyNutritionIntake.carbohydrates.toStringAsFixed(0)} из ${nutrition.dailyNutritionRecommendation.carbohydrates.toStringAsFixed(0)} грамм',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -835,7 +853,10 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, void Function(void Function()) setState) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16) + EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
padding: const EdgeInsets.all(16) +
|
||||
EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -878,6 +899,11 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
selectedGlossary = suggestionsList.first;
|
||||
});
|
||||
}
|
||||
if (suggestionsList.length == 0) {
|
||||
setState(() {
|
||||
enableQuantity = true;
|
||||
});
|
||||
}
|
||||
return suggestionsList;
|
||||
},
|
||||
builder: (context, controller, focusNode) {
|
||||
@@ -888,21 +914,31 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
hintText: 'Введите название продукта/блюда',
|
||||
);
|
||||
},
|
||||
emptyBuilder: (context) => const SizedBox.shrink(),
|
||||
emptyBuilder: (context) {
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
errorBuilder: (context, object) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Нет подходящих вариантов'),
|
||||
),
|
||||
),
|
||||
if (selectedGlossary != null)
|
||||
if (selectedGlossary != null || enableQuantity)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: CustomTextFormField(
|
||||
controller: quantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
hintText: selectedGlossary!.grInPortion == 0 ? '100' : '1',
|
||||
hintText: selectedGlossary == null
|
||||
? '100'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? '100'
|
||||
: '1',
|
||||
autofocus: true,
|
||||
suffixText: selectedGlossary!.grInPortion == 0 ? 'гр' : 'шт',
|
||||
suffixText: selectedGlossary == null
|
||||
? 'гр'
|
||||
: selectedGlossary?.grInPortion == 0
|
||||
? 'гр'
|
||||
: 'шт',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -941,7 +977,11 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
diaryId: diaryDay.id,
|
||||
mealId: diaryDay.meals[currentSelectedMealNumber - 1].id,
|
||||
productName: productNameController.text,
|
||||
portion: selectedGlossary!.grInPortion == 0 ? 'gr' : 'pcs',
|
||||
portion: selectedGlossary == null
|
||||
? 'gr'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? 'gr'
|
||||
: 'pcs',
|
||||
quantity: int.parse(quantityController.text),
|
||||
date: _selectedDay.toString(),
|
||||
);
|
||||
@@ -951,12 +991,27 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
mealId: diaryDay.meals[currentSelectedMealNumber - 1].id,
|
||||
portionId: portionId,
|
||||
productName: productNameController.text,
|
||||
portion: selectedGlossary!.grInPortion == 0 ? 'gr' : 'pcs',
|
||||
portion: selectedGlossary == null
|
||||
? 'gr'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? 'gr'
|
||||
: 'pcs',
|
||||
quantity: int.parse(quantityController.text),
|
||||
date: _selectedDay.toString(),
|
||||
);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
if (enableQuantity) {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
useSafeArea: false,
|
||||
context: context,
|
||||
builder: (context) => GlossaryModerationRequestModalWidget(),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
enableQuantity = false;
|
||||
});
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
@@ -994,6 +1049,7 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedGlossary = null;
|
||||
enableQuantity = false;
|
||||
productNameController.clear();
|
||||
quantityController.clear();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user