forked from eatvio/eatvio_app
feat(diary) Dynamic Meal list and Meal List object
This commit is contained in:
@@ -21,6 +21,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
on<ChangeMealTime>(
|
||||
_changeMealTime); // пользователь изменяет время приема пиши
|
||||
on<ChangeMeal>(_changeMeal);
|
||||
on<WakeupEvent>(_changeWakeup); // пользователь выбирает время пробуждения
|
||||
on<RetireEvent>(_changeRetire); // пользователь выбирает время отхода ко сну
|
||||
on<ToggleMoodExpandedEvent>(_toggleMood);
|
||||
@@ -214,6 +215,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
currentState.mealTimeController = event.time;
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changeMeal(ChangeMeal event, Emitter<DiaryEditState> emit) {}
|
||||
}
|
||||
|
||||
Future<String> uploadImageToServer(String imagePath) async {
|
||||
@@ -241,3 +244,14 @@ TimeOfDay toTime(String timeStr) {
|
||||
TimeOfDay timeOfDay = TimeOfDay(hour: hour, minute: minute);
|
||||
return timeOfDay;
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> fillMealList() {
|
||||
return [
|
||||
SelectionPopupModel(id: 0, title: "Прием пищи 1", isSelected: true),
|
||||
SelectionPopupModel(id: 1, title: "Прием пищи 2"),
|
||||
SelectionPopupModel(id: 2, title: "Прием пищи 3"),
|
||||
SelectionPopupModel(id: 3, title: "Прием пищи 4"),
|
||||
SelectionPopupModel(id: 4, title: "Прием пищи 5"),
|
||||
SelectionPopupModel(id: 5, title: "Прием пищи 6"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -102,3 +102,14 @@ class UploadImages extends DiaryEditEvent {
|
||||
@override
|
||||
List<Object> get props => [image];
|
||||
}
|
||||
|
||||
class ChangeMeal extends DiaryEditEvent {
|
||||
ChangeMeal({required this.value});
|
||||
|
||||
SelectionPopupModel value;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
value,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
this.productNameController,
|
||||
this.productQuantityController,
|
||||
this.selectedMood,
|
||||
this.currentMeal,
|
||||
required this.diaryId,
|
||||
required this.selectedSatiety,
|
||||
required this.wakeupExpanded,
|
||||
@@ -37,6 +38,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
|
||||
DiaryEditModel? diaryEditModelObj;
|
||||
String? diaryDate;
|
||||
SelectionPopupModel? currentMeal;
|
||||
TimeOfDay? wakeupController;
|
||||
TimeOfDay? retireController;
|
||||
TimeOfDay? mealTimeController;
|
||||
@@ -64,10 +66,12 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
selectedSatiety,
|
||||
diaryId,
|
||||
wakeupExpanded,
|
||||
moodExpanded
|
||||
moodExpanded,
|
||||
currentMeal
|
||||
];
|
||||
DiaryEditLoadedState copyWith({
|
||||
DiaryEditModel? diaryEditModelObj,
|
||||
SelectionPopupModel? currentMeal,
|
||||
String? diaryDate,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
@@ -97,6 +101,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
selectedMood: selectedMood ?? this.selectedMood,
|
||||
selectedSatiety: selectedSatiety ?? this.selectedSatiety,
|
||||
diaryId: diaryId ?? this.diaryId,
|
||||
currentMeal: currentMeal ?? this.currentMeal,
|
||||
wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded,
|
||||
moodExpanded: moodExpanded ?? this.moodExpanded);
|
||||
}
|
||||
|
||||
@@ -17,15 +17,6 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
key: key,
|
||||
);
|
||||
|
||||
List<String> mealList = [
|
||||
"Прием пищи 1",
|
||||
"Прием пищи 2",
|
||||
"Прием пищи 3",
|
||||
"Прием пищи 4",
|
||||
"Прием пищи 5",
|
||||
"Прием пищи 6",
|
||||
];
|
||||
|
||||
static Widget builder(BuildContext context) {
|
||||
return BlocProvider<DiaryEditBloc>(
|
||||
create: (context) =>
|
||||
@@ -264,17 +255,25 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
),
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: CustomDropDown(
|
||||
hintText: "Прием пищи",
|
||||
items: mealList,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10.h,
|
||||
vertical: 9.v,
|
||||
),
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: BlocSelector<DiaryEditBloc, DiaryEditState,
|
||||
DiaryEditModel?>(
|
||||
selector: (state) => state.diaryEditModelObj,
|
||||
builder: (context, diaryEditModelObj) {
|
||||
return CustomDropDown(
|
||||
hintText: "Прием пищи",
|
||||
items: diaryEditModelObj?.mealList,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10.h,
|
||||
vertical: 9.v,
|
||||
),
|
||||
onChanged: (value) {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.add(ChangeMeal(value: value));
|
||||
},
|
||||
);
|
||||
})),
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
@@ -948,7 +947,10 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
);
|
||||
if (pickedTime != null && pickedTime != state.wakeupController) {
|
||||
state.wakeupController = pickedTime;
|
||||
context.read<DiaryEditBloc>().add(ChangeMealTime(state.diaryId, pickedTime, ));
|
||||
context.read<DiaryEditBloc>().add(ChangeMealTime(
|
||||
state.diaryId,
|
||||
pickedTime,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart';
|
||||
|
||||
/// This class defines the variables used in the [k0_page],
|
||||
/// and is typically used to hold data that is passed between different parts of the application.
|
||||
class DiaryEditModel extends Equatable {
|
||||
DiaryEditModel();
|
||||
DiaryEditModel({this.mealList = const []});
|
||||
|
||||
List<SelectionPopupModel> mealList;
|
||||
DiaryEditModel copyWith() {
|
||||
return DiaryEditModel();
|
||||
return DiaryEditModel(
|
||||
mealList: mealList,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
List<Object?> get props => [mealList];
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class CustomDropDown extends StatelessWidget {
|
||||
|
||||
final TextStyle? textStyle;
|
||||
|
||||
final List<String>? items;
|
||||
final List<SelectionPopupModel>? items;
|
||||
|
||||
final String? hintText;
|
||||
|
||||
@@ -61,9 +61,9 @@ class CustomDropDown extends StatelessWidget {
|
||||
|
||||
final bool? filled;
|
||||
|
||||
final FormFieldValidator<String>? validator;
|
||||
final FormFieldValidator<SelectionPopupModel>? validator;
|
||||
|
||||
final Function(String)? onChanged;
|
||||
final Function(SelectionPopupModel)? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -77,50 +77,67 @@ class CustomDropDown extends StatelessWidget {
|
||||
|
||||
Widget get dropDownWidget => SizedBox(
|
||||
width: width ?? double.maxFinite,
|
||||
child: DropdownButtonFormField(
|
||||
child: DropdownButtonFormField<SelectionPopupModel>(
|
||||
focusNode: focusNode ?? FocusNode(),
|
||||
icon: icon,
|
||||
autofocus: autofocus!,
|
||||
items: items?.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
style: textStyle ?? theme.textTheme.titleMedium,
|
||||
items: items?.map((SelectionPopupModel item) {
|
||||
return DropdownMenuItem<SelectionPopupModel>(
|
||||
value: item,
|
||||
child: Text(
|
||||
value,
|
||||
item.title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: hintStyle ?? theme.textTheme.titleMedium,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
decoration: decoration,
|
||||
validator: validator,
|
||||
onChanged: (value) {
|
||||
onChanged!(value.toString());
|
||||
onChanged!(value!);
|
||||
},
|
||||
),
|
||||
);
|
||||
InputDecoration get decoration => InputDecoration(
|
||||
hintText: hintText ?? "",
|
||||
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||
hintStyle: hintStyle ?? theme.textTheme.titleMedium,
|
||||
prefixIcon: prefix,
|
||||
prefixIconConstraints: prefixConstraints,
|
||||
suffixIcon: suffix,
|
||||
suffixIconConstraints: suffixConstraints,
|
||||
isDense: true,
|
||||
contentPadding: contentPadding ?? EdgeInsets.all(6.h),
|
||||
fillColor: fillColor,
|
||||
contentPadding: contentPadding ??
|
||||
EdgeInsets.only(
|
||||
left: 6.h,
|
||||
top: 6.v,
|
||||
bottom: 6.v,
|
||||
),
|
||||
fillColor: fillColor ?? theme.colorScheme.onPrimary,
|
||||
filled: filled,
|
||||
border: borderDecoration ??
|
||||
OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
borderSide: BorderSide.none,
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
enabledBorder: borderDecoration ??
|
||||
OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
borderSide: BorderSide(color: Colors.grey, width: 1)),
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
focusedBorder: borderDecoration ??
|
||||
OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(5.h),
|
||||
borderSide: BorderSide(color: Colors.grey, width: 1),
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user