forked from eatvio/eatvio_app
feat(profile): subscribers and subscriptions
This commit is contained in:
@@ -12,7 +12,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
class DiaryCubit extends Cubit<DiaryState> {
|
||||
final DiaryRepository diaryRepository;
|
||||
final GlossaryRepository glossaryRepository;
|
||||
double currentSelectedSatietyRating = 3;
|
||||
|
||||
DiaryCubit({
|
||||
required this.diaryRepository,
|
||||
@@ -22,11 +21,16 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
getDiaryDay(String date, [bool needLoading = true]) async {
|
||||
if (needLoading) emit(const DiaryState.loading());
|
||||
try {
|
||||
final diaryDay = await diaryRepository.getDiaryByDate(date);
|
||||
final List<int> satiety = [];
|
||||
for (int i = 0; i < diaryDay.meals.length; i++) {
|
||||
satiety.add(diaryDay.meals[i].satiety);
|
||||
}
|
||||
emit(
|
||||
DiaryState.loaded(
|
||||
diary: await diaryRepository.getDiaryByDate(date),
|
||||
diary: diaryDay,
|
||||
nutrition: await getNutrition((await diaryRepository.getDiaryByDate(date)).id),
|
||||
currentSelectedSatietyRating: currentSelectedSatietyRating,
|
||||
currentSelectedSatietyRating: satiety,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -136,17 +140,23 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
await getDiaryDay(date, false);
|
||||
}
|
||||
|
||||
updateCurrentSelectedSatietyRating(double value) {
|
||||
currentSelectedSatietyRating = value;
|
||||
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating));
|
||||
updateCurrentSelectedSatietyRating({
|
||||
required int diaryId,
|
||||
required int meal,
|
||||
required int value,
|
||||
}) {
|
||||
List<int> satiety = [...(state as DiaryStateLoaded).currentSelectedSatietyRating];
|
||||
satiety[meal] = value;
|
||||
diaryRepository.fillSatiety(diaryId: diaryId, meal: meal, satiety: value.toInt() - 1);
|
||||
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: satiety));
|
||||
}
|
||||
|
||||
sendProductToModeration({
|
||||
required String name,
|
||||
required int energy,
|
||||
required int proteins,
|
||||
required int fats,
|
||||
required int carbohydrates,
|
||||
required double energy,
|
||||
required double proteins,
|
||||
required double fats,
|
||||
required double carbohydrates,
|
||||
}) async {
|
||||
return await diaryRepository.sendProductToModeration(
|
||||
name: name,
|
||||
|
||||
@@ -17,6 +17,6 @@ class DiaryState with _$DiaryState {
|
||||
const factory DiaryState.loaded({
|
||||
required DiaryDayModel diary,
|
||||
required NutritionDataModel nutrition,
|
||||
required double currentSelectedSatietyRating,
|
||||
required List<int> currentSelectedSatietyRating,
|
||||
}) = DiaryStateLoaded;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ mixin _$DiaryState {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String errorMessage) error,
|
||||
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)
|
||||
List<int> currentSelectedSatietyRating)
|
||||
loaded,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -32,7 +32,7 @@ mixin _$DiaryState {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -42,7 +42,7 @@ mixin _$DiaryState {
|
||||
TResult Function()? loading,
|
||||
TResult Function(String errorMessage)? error,
|
||||
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@@ -140,7 +140,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String errorMessage) error,
|
||||
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)
|
||||
List<int> currentSelectedSatietyRating)
|
||||
loaded,
|
||||
}) {
|
||||
return $default();
|
||||
@@ -153,7 +153,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
}) {
|
||||
return $default?.call();
|
||||
@@ -166,7 +166,7 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TResult Function()? loading,
|
||||
TResult Function(String errorMessage)? error,
|
||||
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -263,7 +263,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String errorMessage) error,
|
||||
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)
|
||||
List<int> currentSelectedSatietyRating)
|
||||
loaded,
|
||||
}) {
|
||||
return loading();
|
||||
@@ -276,7 +276,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
}) {
|
||||
return loading?.call();
|
||||
@@ -289,7 +289,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TResult Function()? loading,
|
||||
TResult Function(String errorMessage)? error,
|
||||
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -415,7 +415,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String errorMessage) error,
|
||||
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)
|
||||
List<int> currentSelectedSatietyRating)
|
||||
loaded,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
@@ -428,7 +428,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
@@ -441,7 +441,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TResult Function()? loading,
|
||||
TResult Function(String errorMessage)? error,
|
||||
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -511,7 +511,7 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
|
||||
$Res call(
|
||||
{DiaryDayModel diary,
|
||||
NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating});
|
||||
List<int> currentSelectedSatietyRating});
|
||||
|
||||
$DiaryDayModelCopyWith<$Res> get diary;
|
||||
$NutritionDataModelCopyWith<$Res> get nutrition;
|
||||
@@ -544,9 +544,9 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
: nutrition // ignore: cast_nullable_to_non_nullable
|
||||
as NutritionDataModel,
|
||||
currentSelectedSatietyRating: null == currentSelectedSatietyRating
|
||||
? _value.currentSelectedSatietyRating
|
||||
? _value._currentSelectedSatietyRating
|
||||
: currentSelectedSatietyRating // ignore: cast_nullable_to_non_nullable
|
||||
as double,
|
||||
as List<int>,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -577,14 +577,21 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
const _$DiaryStateLoadedImpl(
|
||||
{required this.diary,
|
||||
required this.nutrition,
|
||||
required this.currentSelectedSatietyRating});
|
||||
required final List<int> currentSelectedSatietyRating})
|
||||
: _currentSelectedSatietyRating = currentSelectedSatietyRating;
|
||||
|
||||
@override
|
||||
final DiaryDayModel diary;
|
||||
@override
|
||||
final NutritionDataModel nutrition;
|
||||
final List<int> _currentSelectedSatietyRating;
|
||||
@override
|
||||
final double currentSelectedSatietyRating;
|
||||
List<int> get currentSelectedSatietyRating {
|
||||
if (_currentSelectedSatietyRating is EqualUnmodifiableListView)
|
||||
return _currentSelectedSatietyRating;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_currentSelectedSatietyRating);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -599,15 +606,14 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
(identical(other.diary, diary) || other.diary == diary) &&
|
||||
(identical(other.nutrition, nutrition) ||
|
||||
other.nutrition == nutrition) &&
|
||||
(identical(other.currentSelectedSatietyRating,
|
||||
currentSelectedSatietyRating) ||
|
||||
other.currentSelectedSatietyRating ==
|
||||
currentSelectedSatietyRating));
|
||||
const DeepCollectionEquality().equals(
|
||||
other._currentSelectedSatietyRating,
|
||||
_currentSelectedSatietyRating));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, diary, nutrition, currentSelectedSatietyRating);
|
||||
int get hashCode => Object.hash(runtimeType, diary, nutrition,
|
||||
const DeepCollectionEquality().hash(_currentSelectedSatietyRating));
|
||||
|
||||
/// Create a copy of DiaryState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -625,7 +631,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String errorMessage) error,
|
||||
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)
|
||||
List<int> currentSelectedSatietyRating)
|
||||
loaded,
|
||||
}) {
|
||||
return loaded(diary, nutrition, currentSelectedSatietyRating);
|
||||
@@ -638,7 +644,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
}) {
|
||||
return loaded?.call(diary, nutrition, currentSelectedSatietyRating);
|
||||
@@ -651,7 +657,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TResult Function()? loading,
|
||||
TResult Function(String errorMessage)? error,
|
||||
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
|
||||
double currentSelectedSatietyRating)?
|
||||
List<int> currentSelectedSatietyRating)?
|
||||
loaded,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -703,12 +709,12 @@ abstract class DiaryStateLoaded implements DiaryState {
|
||||
const factory DiaryStateLoaded(
|
||||
{required final DiaryDayModel diary,
|
||||
required final NutritionDataModel nutrition,
|
||||
required final double currentSelectedSatietyRating}) =
|
||||
required final List<int> currentSelectedSatietyRating}) =
|
||||
_$DiaryStateLoadedImpl;
|
||||
|
||||
DiaryDayModel get diary;
|
||||
NutritionDataModel get nutrition;
|
||||
double get currentSelectedSatietyRating;
|
||||
List<int> get currentSelectedSatietyRating;
|
||||
|
||||
/// Create a copy of DiaryState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
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';
|
||||
@@ -18,7 +19,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
import 'package:syncfusion_flutter_gauges/gauges.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
|
||||
@@ -42,7 +42,6 @@ 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() {
|
||||
@@ -124,7 +123,7 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
child: Column(
|
||||
children: [
|
||||
_calendar(state),
|
||||
if (state is DiaryStateLoading) _loader(),
|
||||
if (state is DiaryStateLoading) const Loader(),
|
||||
if (state is DiaryStateLoaded)
|
||||
_meals(
|
||||
state.diary,
|
||||
@@ -249,7 +248,7 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
|
||||
_meals(
|
||||
DiaryDayModel diaryDay,
|
||||
double currentSelectedSatietyRating,
|
||||
List<int> satietyRating,
|
||||
) {
|
||||
return Material(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
@@ -322,7 +321,9 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
_selectedDay!.compareTo(today!) == 1
|
||||
? const SizedBox.shrink()
|
||||
: SatietyRatingWidget(
|
||||
currentSelectedSatietyRating: currentSelectedSatietyRating,
|
||||
currentSelectedSatietyRating: satietyRating,
|
||||
diaryId: diaryDay.id,
|
||||
meal: currentSelectedMealNumber,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -767,18 +768,6 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
_loader() {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
height: 32,
|
||||
width: 32,
|
||||
child: RiveAnimation.asset(
|
||||
'assets/rive_animations/loading.riv',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_calendar(DiaryState state) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -883,76 +872,74 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TypeAheadField(
|
||||
controller: productNameController,
|
||||
itemBuilder: (context, glossary) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
glossary.name,
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
fontSize: 16,
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.8 - 32,
|
||||
child: TypeAheadField(
|
||||
controller: productNameController,
|
||||
itemBuilder: (context, glossary) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
glossary.name,
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemSeparatorBuilder: (context, index) => _divider(context),
|
||||
onSelected: (newSelectedGlossary) async {
|
||||
setState(() {
|
||||
selectedGlossary = newSelectedGlossary;
|
||||
productNameController.text = selectedGlossary!.name;
|
||||
});
|
||||
},
|
||||
suggestionsCallback: (query) async {
|
||||
if (query.length < 1) return [];
|
||||
final suggestionsList = await diaryCubit.getGlossaryListByQuery(query);
|
||||
return suggestionsList;
|
||||
},
|
||||
builder: (context, controller, focusNode) {
|
||||
return CustomTextFormField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
focusNode: focusNode,
|
||||
hintText: 'Введите название продукта/блюда',
|
||||
);
|
||||
},
|
||||
emptyBuilder: (context) {
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
errorBuilder: (context, object) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Нет подходящих вариантов'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemSeparatorBuilder: (context, index) => _divider(context),
|
||||
onSelected: (newSelectedGlossary) async {
|
||||
setState(() {
|
||||
selectedGlossary = newSelectedGlossary;
|
||||
productNameController.text = selectedGlossary!.name;
|
||||
});
|
||||
},
|
||||
suggestionsCallback: (query) async {
|
||||
if (query.length < 1) return [];
|
||||
final suggestionsList = await diaryCubit.getGlossaryListByQuery(query);
|
||||
if (suggestionsList.length == 1) {
|
||||
setState(() {
|
||||
selectedGlossary = suggestionsList.first;
|
||||
});
|
||||
}
|
||||
if (suggestionsList.length == 0) {
|
||||
setState(() {
|
||||
enableQuantity = true;
|
||||
});
|
||||
}
|
||||
return suggestionsList;
|
||||
},
|
||||
builder: (context, controller, focusNode) {
|
||||
return CustomTextFormField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
focusNode: focusNode,
|
||||
hintText: 'Введите название продукта/блюда',
|
||||
);
|
||||
},
|
||||
emptyBuilder: (context) {
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
errorBuilder: (context, object) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Нет подходящих вариантов'),
|
||||
),
|
||||
),
|
||||
if (selectedGlossary != null || enableQuantity)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: CustomTextFormField(
|
||||
controller: quantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
hintText: selectedGlossary == null
|
||||
? '100'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? '100'
|
||||
: '1',
|
||||
suffixText: selectedGlossary == null
|
||||
? 'гр'
|
||||
: selectedGlossary?.grInPortion == 0
|
||||
? 'гр'
|
||||
: 'шт',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.2 - 4,
|
||||
child: CustomTextFormField(
|
||||
controller: quantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
hintText: selectedGlossary == null
|
||||
? '100'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? '100'
|
||||
: '1',
|
||||
suffixText: selectedGlossary == null
|
||||
? 'гр'
|
||||
: selectedGlossary?.grInPortion == 0
|
||||
? 'гр'
|
||||
: 'шт',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
@@ -1013,7 +1000,7 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
if (enableQuantity) {
|
||||
if (selectedGlossary == null) {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
useRootNavigator: true,
|
||||
@@ -1029,9 +1016,6 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
enableQuantity = false;
|
||||
});
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
@@ -1070,7 +1054,6 @@ class _DiaryScreenState extends State<DiaryScreen> {
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedGlossary = null;
|
||||
enableQuantity = false;
|
||||
productNameController.clear();
|
||||
quantityController.clear();
|
||||
});
|
||||
|
||||
@@ -264,10 +264,10 @@ class _GlossaryModerationRequestModalWidgetState extends State<GlossaryModeratio
|
||||
onTap: () {
|
||||
widget.diaryCubit.sendProductToModeration(
|
||||
name: productNameController.text,
|
||||
energy: int.parse(energyController.text),
|
||||
proteins: int.parse(proteinsController.text),
|
||||
fats: int.parse(fatsController.text),
|
||||
carbohydrates: int.parse(carbohydratesController.text),
|
||||
energy: double.parse(energyController.text),
|
||||
proteins: double.parse(proteinsController.text),
|
||||
fats: double.parse(fatsController.text),
|
||||
carbohydrates: double.parse(carbohydratesController.text),
|
||||
);
|
||||
setState(() {
|
||||
glossaryState = GlossaryState.success;
|
||||
|
||||
@@ -5,11 +5,15 @@ import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
class SatietyRatingWidget extends StatefulWidget {
|
||||
final double currentSelectedSatietyRating;
|
||||
final List<int> currentSelectedSatietyRating;
|
||||
final int diaryId;
|
||||
final int meal;
|
||||
|
||||
const SatietyRatingWidget({
|
||||
super.key,
|
||||
required this.currentSelectedSatietyRating,
|
||||
required this.diaryId,
|
||||
required this.meal,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -39,7 +43,7 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
|
||||
width: 32,
|
||||
),
|
||||
RatingBar.builder(
|
||||
initialRating: 3,
|
||||
initialRating: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1,
|
||||
itemCount: 6,
|
||||
itemSize: MediaQuery.of(context).size.width / 6 - (124 / 6),
|
||||
updateOnDrag: true,
|
||||
@@ -49,17 +53,17 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 1 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 1 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFC82222),
|
||||
border: widget.currentSelectedSatietyRating == 1
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 1
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFFAA3333),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 1
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 1
|
||||
? BorderRadius.horizontal(
|
||||
left: Radius.circular(8),
|
||||
right: Radius.circular(2),
|
||||
@@ -73,85 +77,85 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 2 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 2 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFFF3E3E),
|
||||
border: widget.currentSelectedSatietyRating == 2
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 2
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFF550000),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 2 ? BorderRadius.circular(2) : null,
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 2 ? BorderRadius.circular(2) : null,
|
||||
),
|
||||
);
|
||||
case 2:
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 3 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 3 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFF8C926),
|
||||
border: widget.currentSelectedSatietyRating == 3
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 3
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFF8C5D00),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 3 ? BorderRadius.circular(2) : null,
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 3 ? BorderRadius.circular(2) : null,
|
||||
),
|
||||
);
|
||||
case 3:
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 4 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 4 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFFFF3BF),
|
||||
border: widget.currentSelectedSatietyRating == 4
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 4
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFFB5911B),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 4 ? BorderRadius.circular(2) : null,
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 4 ? BorderRadius.circular(2) : null,
|
||||
),
|
||||
);
|
||||
case 4:
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 5 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 5 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFF62E833),
|
||||
border: widget.currentSelectedSatietyRating == 5
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 5
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFF276918),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 5 ? BorderRadius.circular(2) : null,
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 5 ? BorderRadius.circular(2) : null,
|
||||
),
|
||||
);
|
||||
default:
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width / 6,
|
||||
height: 24,
|
||||
margin: widget.currentSelectedSatietyRating == 6 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
margin: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 6 ? EdgeInsets.symmetric(horizontal: 2) : null,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFF4DCE20),
|
||||
border: widget.currentSelectedSatietyRating == 6
|
||||
border: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 6
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Color(0xFF184D12),
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
borderRadius: widget.currentSelectedSatietyRating == 6
|
||||
borderRadius: widget.currentSelectedSatietyRating[widget.meal - 1].toDouble() + 1 == 6
|
||||
? BorderRadius.horizontal(
|
||||
left: Radius.circular(2),
|
||||
right: Radius.circular(8),
|
||||
@@ -163,7 +167,11 @@ class _SatietyRatingWidgetState extends State<SatietyRatingWidget> {
|
||||
);
|
||||
}
|
||||
},
|
||||
onRatingUpdate: (value) => context.read<DiaryCubit>().updateCurrentSelectedSatietyRating(value),
|
||||
onRatingUpdate: (value) => context.read<DiaryCubit>().updateCurrentSelectedSatietyRating(
|
||||
diaryId: widget.diaryId,
|
||||
meal: widget.meal,
|
||||
value: value.toInt(),
|
||||
),
|
||||
),
|
||||
SvgPicture.asset(
|
||||
'assets/icons/satiety_emoji_right.svg',
|
||||
|
||||
Reference in New Issue
Block a user