forked from eatvio/eatvio_app
feat(diary) More events for api methods. Stump for photo upload
This commit is contained in:
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 6.2 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 5.9 KiB |
@@ -103,7 +103,7 @@ class AuthScreen extends StatelessWidget {
|
||||
box.put('token', token);
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.diaryEdit,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
|
||||
@@ -16,9 +16,15 @@ part 'diary_edit_state.dart';
|
||||
class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
DiaryEditBloc(DiaryEditState initialState) : super(initialState) {
|
||||
on<DiaryEditInitialEvent>(_onInitialize);
|
||||
on<ChangeSatiety>(_changeSatiety);
|
||||
on<MoodEvent>(_changeMood);
|
||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
on<WakeupEvent>(_changeWakeup); // пользователь выбирает время пробуждения
|
||||
on<RetireEvent>(_changeRetire); // пользователь выбирает время отхода ко сну
|
||||
on<ToggleMoodExpandedEvent>(_toggleMood);
|
||||
on<ToggleWakeupExpandedEvent>(_toggleWakeup);
|
||||
on<AddPortionEvent>(_addPortion); //пользователь нажимает "Добавить продукт"
|
||||
on<RemovePortionEvent>(
|
||||
_removePortion); // пользователь нажимает на крестик около продукта
|
||||
}
|
||||
|
||||
Future<void> _onInitialize(
|
||||
@@ -105,7 +111,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
}
|
||||
|
||||
Future<void> _changeMood(
|
||||
MoodEvent event, Emitter<DiaryEditState> emit) async {
|
||||
ChangeMood event, Emitter<DiaryEditState> emit) async {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
@@ -124,4 +130,43 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
print(currentState.moodExpanded);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _toggleWakeup(
|
||||
ToggleWakeupExpandedEvent event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
emit(currentState.copyWith(wakeupExpanded: !currentState.wakeupExpanded));
|
||||
currentState.wakeupExpanded = !currentState.wakeupExpanded;
|
||||
print(currentState.wakeupExpanded);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changeWakeup(
|
||||
WakeupEvent event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
emit(currentState.copyWith(wakeupController: event.selectedTime));
|
||||
currentState.wakeupController = event.selectedTime;
|
||||
print(currentState.wakeupExpanded);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changeRetire(
|
||||
RetireEvent event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
emit(currentState.copyWith(retireController: event.selectedTime));
|
||||
currentState.retireController = event.selectedTime;
|
||||
print(currentState.retireController);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _addPortion(
|
||||
AddPortionEvent event, Emitter<DiaryEditState> emit) {}
|
||||
|
||||
FutureOr<void> _removePortion(
|
||||
RemovePortionEvent event, Emitter<DiaryEditState> emit) {}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,53 @@ class ChangeSatiety extends DiaryEditEvent {
|
||||
List<Object> get props => [selectedElement];
|
||||
}
|
||||
|
||||
class MoodEvent extends DiaryEditEvent {
|
||||
MoodEvent(this.selectedElement);
|
||||
class ChangeMood extends DiaryEditEvent {
|
||||
ChangeMood(this.selectedElement);
|
||||
final int selectedElement;
|
||||
|
||||
@override
|
||||
List<Object> get props => [selectedElement];
|
||||
}
|
||||
|
||||
class WakeupEvent extends DiaryEditEvent {
|
||||
WakeupEvent(this.selectedTime);
|
||||
final TimeOfDay selectedTime;
|
||||
|
||||
@override
|
||||
List<Object> get props => [selectedTime];
|
||||
}
|
||||
|
||||
class RetireEvent extends DiaryEditEvent {
|
||||
RetireEvent(this.selectedTime);
|
||||
final TimeOfDay selectedTime;
|
||||
|
||||
@override
|
||||
List<Object> get props => [selectedTime];
|
||||
}
|
||||
|
||||
class ToggleMoodExpandedEvent extends DiaryEditEvent {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ToggleWakeupExpandedEvent extends DiaryEditEvent {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class AddPortionEvent extends DiaryEditEvent {
|
||||
AddPortionEvent(this.mealId, this.productId, this.quantity, this.portion);
|
||||
final int mealId;
|
||||
final int productId;
|
||||
final int quantity;
|
||||
final String portion;
|
||||
@override
|
||||
List<Object> get props => [mealId, productId, quantity];
|
||||
}
|
||||
|
||||
class RemovePortionEvent extends DiaryEditEvent {
|
||||
RemovePortionEvent(this.portionId);
|
||||
final int portionId;
|
||||
@override
|
||||
List<Object> get props => [portionId];
|
||||
}
|
||||
|
||||
@@ -274,7 +274,9 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
SizedBox(height: 30.v),
|
||||
_buildAddProduct(context),
|
||||
SizedBox(height: 30.v),
|
||||
//_buildAddPhoto(context),
|
||||
_buildProduct(context),
|
||||
SizedBox(height: 30.v),
|
||||
_buildAddPhoto(context),
|
||||
Text(
|
||||
"Ваша сытость после приёма пищи",
|
||||
style: CustomTextStyles.bodyMediumBlack900,
|
||||
@@ -363,7 +365,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
top: 5.v,
|
||||
),
|
||||
child: Text(
|
||||
"Сырный суп",
|
||||
"Omelette",
|
||||
style: CustomTextStyles.titleMedium16,
|
||||
),
|
||||
),
|
||||
@@ -374,7 +376,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
bottom: 3.v,
|
||||
),
|
||||
child: Text(
|
||||
"400мл",
|
||||
"15гр",
|
||||
style: CustomTextStyles.titleMedium16,
|
||||
),
|
||||
),
|
||||
@@ -713,8 +715,8 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
/*BlocProvider.of<DiaryEditBloc>(context)
|
||||
.add(ToggleWakeupExpandedEvent());*/
|
||||
BlocProvider.of<DiaryEditBloc>(context)
|
||||
.add(ToggleWakeupExpandedEvent());
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -740,7 +742,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
child: TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Во сколько вы просунились?',
|
||||
suffixIcon: Icon(Icons.access_time),
|
||||
prefixIcon: Icon(Icons.sunny),
|
||||
),
|
||||
initialValue: state.wakeupController.toString(),
|
||||
),
|
||||
@@ -752,7 +754,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
child: TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Во сколько вы легли спать?',
|
||||
suffixIcon: Icon(Icons.access_time),
|
||||
prefixIcon: Icon(Icons.bed),
|
||||
),
|
||||
initialValue: state.retireController.toString(),
|
||||
),
|
||||
@@ -829,32 +831,44 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
ScaleElement(
|
||||
color: Colors.red,
|
||||
isSelected: state.selectedMood == 0,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(0));
|
||||
},
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.orange,
|
||||
isSelected: state.selectedMood == 1,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(1));
|
||||
},
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.yellow,
|
||||
isSelected: state.selectedMood == 2,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(2));
|
||||
},
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lime,
|
||||
isSelected: state.selectedMood == 3,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(3));
|
||||
},
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lightGreen,
|
||||
isSelected: state.selectedMood == 4,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(4));
|
||||
},
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.green,
|
||||
isSelected: state.selectedMood == 5,
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(5));
|
||||
},
|
||||
),
|
||||
Text("😊"),
|
||||
// Остальные элементы шкалы
|
||||
|
||||
Reference in New Issue
Block a user