forked from eatvio/eatvio_app
fix(diet): diet states
This commit is contained in:
@@ -190,7 +190,7 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
||||
children: [
|
||||
CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft, state.dietStateIndex ?? 0);
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||
if (widget.diet != null) {
|
||||
final result = await context.read<CreateDietCubit>().updateDiet(
|
||||
widget.diet!.id,
|
||||
|
||||
@@ -19,7 +19,6 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
final GlossaryRepository glossaryRepository;
|
||||
String? tempImagePath;
|
||||
int? dietId;
|
||||
static const _dietStateValues = DietState.values;
|
||||
|
||||
CreateDietCubit({required this.profileRepository, required this.createDietRepository, required this.glossaryRepository}) : super(CreateDietState.initial());
|
||||
|
||||
@@ -39,7 +38,6 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
}
|
||||
|
||||
final dietStateIndex = _dietStateValues.indexOf(diet.state);
|
||||
final type = Map<String, bool>.fromIterable(dietTypeValues, value: (element) => false);
|
||||
type['meat'] = diet.type.meat ?? false;
|
||||
type['veg'] = diet.type.veg ?? false;
|
||||
@@ -56,7 +54,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
imageUrl: '$baseUrl/storage/${diet.image}',
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(dietStateIndex: dietStateIndex, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
emit(state.copyWith(dietState: diet.state, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
emit(state.copyWith(isLoading: true));
|
||||
}
|
||||
|
||||
@@ -130,8 +128,8 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
emit(state.copyWith(dietData: state.dietData.copyWith(dailySchedule: dailySchedule), dietDurationError: null));
|
||||
}
|
||||
|
||||
void setDietState(DietState dietState, int index) {
|
||||
emit(state.copyWith(dietData: state.dietData.copyWith(state: dietState), dietStateIndex: index, dietStateError: null));
|
||||
void setDietState(DietState dietState) {
|
||||
emit(state.copyWith(dietData: state.dietData.copyWith(state: dietState), dietState: dietState, dietStateError: null));
|
||||
}
|
||||
|
||||
void setDietType({required String key, required bool value}) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreateDietState with _$CreateDietState {
|
||||
String? dietImageError,
|
||||
required List<String> dailyScheduleErrors,
|
||||
int? durationIndex,
|
||||
int? dietStateIndex,
|
||||
DietState? dietState,
|
||||
@Default(false) bool published,
|
||||
@Default(false) bool drafted,
|
||||
@Default(false) bool isDietBeingEdited,
|
||||
|
||||
@@ -58,9 +58,9 @@ class _StatusDropDownWidgetState extends State<StatusDropDownWidget> {
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
if (value == s.public_diet_state) {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.active, 0);
|
||||
context.read<CreateDietCubit>().setDietState(DietState.active);
|
||||
} else {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.personal, 1);
|
||||
context.read<CreateDietCubit>().setDietState(DietState.personal);
|
||||
}
|
||||
// final index = dietStates.indexOf(value);
|
||||
// context.read<CreateDietCubit>().setDietState(value, index);
|
||||
@@ -77,7 +77,7 @@ class _StatusDropDownWidgetState extends State<StatusDropDownWidget> {
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: state.dietStateIndex == null ? null : dietStateTitles[state.dietStateIndex ?? 0],
|
||||
value: state.dietState == DietState.active ? dietStateTitles[0] : state.dietState == DietState.personal ? dietStateTitles[1] : null,
|
||||
),
|
||||
if (state.dietStateError != null) ...[
|
||||
const SizedBox(
|
||||
|
||||
Reference in New Issue
Block a user