fixed profile, recipeis and diets

This commit is contained in:
Username1548
2025-02-10 21:50:13 +07:00
parent 5ea3264474
commit 070d7e1047
51 changed files with 1382 additions and 1360 deletions

View File

@@ -1,5 +1,8 @@
import 'dart:developer';
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.dart';
import 'package:eatvio_app/features/my_diets/repositories/my_diets_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -28,6 +31,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
'name',
'name:desc',
];
static const List<int?> _durationValues = [null, ...durationValues];
static const List<String?> _types = [null, ...dietTypeValues];
@@ -39,7 +43,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _activeQuery,
),
);
@@ -48,7 +52,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _draftQuery,
),
);
@@ -57,7 +61,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _personalQuery,
),
);
@@ -70,7 +74,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _activeQuery,
),
);
@@ -79,7 +83,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _draftQuery,
),
);
@@ -88,7 +92,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _personalQuery,
),
);
@@ -101,7 +105,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _activeQuery,
),
);
@@ -110,7 +114,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _draftQuery,
),
);
@@ -119,7 +123,7 @@ class MyDietsCubit extends Cubit<MyDietsState> {
EasyDebounce.debounce(
'loadDiets',
Duration(seconds: 1),
() => loadDiets(
() => loadCurrentDiets(
query: _personalQuery,
),
);
@@ -128,9 +132,34 @@ class MyDietsCubit extends Cubit<MyDietsState> {
void changeSelectedStateIndex(int index) {
emit(state.copyWith(selectedStateIndex: index));
if (state.activeDiets.isEmpty) {
EasyDebounce.debounce(
'loadActiveDiets',
Duration(seconds: 1),
() => loadCurrentDiets(
query: _activeQuery,
),
);
} else if (state.draftDiets.isEmpty) {
EasyDebounce.debounce(
'loadDraftDiets',
Duration(seconds: 1),
() => loadCurrentDiets(
query: _draftQuery,
),
);
} else if (state.personalDiets.isEmpty) {
EasyDebounce.debounce(
'loadPersonalDiets',
Duration(seconds: 1),
() => loadCurrentDiets(
query: _personalQuery,
),
);
}
}
Future<void> loadDiets({
Future<void> loadCurrentDiets({
String? query,
}) async {
switch (state.selectedStateIndex) {
@@ -160,11 +189,13 @@ class MyDietsCubit extends Cubit<MyDietsState> {
final type = _types[state.activeFilterState.typeIndex];
final duration = _durationValues[state.activeFilterState.durationIndex];
final sorting = _sortingValues[state.activeFilterState.sortingIndex];
final dietState = DietState.active;
final dietsPagination = await myDietsRepository.getDiets(
query: query,
types: type,
duration: duration,
sorting: sorting,
state: dietState.toString(),
);
lastActivePage = dietsPagination.meta.lastPage;
emit(
@@ -174,7 +205,8 @@ class MyDietsCubit extends Cubit<MyDietsState> {
error: null,
),
);
} catch (e) {
} catch (e, st) {
log(e.toString(), stackTrace: st);
emit(
state.copyWith(error: e.toString()),
);
@@ -187,11 +219,13 @@ class MyDietsCubit extends Cubit<MyDietsState> {
final type = _types[state.draftFilterState.typeIndex];
final duration = _durationValues[state.draftFilterState.durationIndex];
final sorting = _sortingValues[state.draftFilterState.sortingIndex];
final dietState = DietState.draft;
final dietsPagination = await myDietsRepository.getDiets(
query: query,
types: type,
duration: duration,
sorting: sorting,
state: dietState.toString(),
);
lastActivePage = dietsPagination.meta.lastPage;
emit(
@@ -214,11 +248,13 @@ class MyDietsCubit extends Cubit<MyDietsState> {
final type = _types[state.personalFilterState.typeIndex];
final duration = _durationValues[state.personalFilterState.durationIndex];
final sorting = _sortingValues[state.personalFilterState.sortingIndex];
final dietState = DietState.personal;
final dietsPagination = await myDietsRepository.getDiets(
query: query,
types: type,
duration: duration,
sorting: sorting,
state: dietState.toString(),
);
lastActivePage = dietsPagination.meta.lastPage;
emit(

View File

@@ -33,7 +33,7 @@ class MyDietsScreenContent extends StatelessWidget {
final activeDietsScrollController = ScrollController();
final draftDietsScrollController = ScrollController();
final personalDietsScrollController = ScrollController();
final activeDietsSearchController = SearchController();
final draftDietsSearchController = SearchController();
final personalDietsSearchController = SearchController();
@@ -111,7 +111,7 @@ class MyDietsScreenContent extends StatelessWidget {
'searchDiets',
Duration(milliseconds: 500),
() {
context.read<MyDietsCubit>().loadDiets(query: query == '' ? null : query);
context.read<MyDietsCubit>().loadCurrentDiets(query: query == '' ? null : query);
},
);
},
@@ -133,7 +133,7 @@ class MyDietsScreenContent extends StatelessWidget {
];
},
body: RefreshIndicator(
onRefresh: () => context.read<MyDietsCubit>().loadDiets(),
onRefresh: () => context.read<MyDietsCubit>().loadCurrentDiets(),
child: BlocBuilder<MyDietsCubit, MyDietsState>(
builder: (BuildContext context, MyDietsState state) {
if (state.isLoading) {

View File

@@ -6,6 +6,7 @@ import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart';
import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/widgets/info_row.dart';
import 'package:eatvio_app/features/create_diet/presentation/create_diet_screen.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_cubit.dart';
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.dart';
@@ -110,6 +111,13 @@ class _MyDietWidgetState extends State<MyDietWidget> {
children: [
Expanded(
child: CustomOutlinedButton(
onPressed: () {
if (state.selectedStateIndex == 1) {
} else if (state.selectedStateIndex == 2) {
} else {
GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: widget.diet);
}
},
text: switch (state.selectedStateIndex) {
1 => s.publish,
2 => s.toOffer,
@@ -160,6 +168,12 @@ class _MyDietWidgetState extends State<MyDietWidget> {
children: [
Expanded(
child: CustomOutlinedButton(
onPressed: () {
if (state.selectedStateIndex == 0) {
} else {
GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: widget.diet);
}
},
text: switch (state.selectedStateIndex) {
0 => s.removeFromActive,
_ => s.edit,
@@ -178,51 +192,49 @@ class _MyDietWidgetState extends State<MyDietWidget> {
onPressed: () async {
final result = await context.read<MyDietsCubit>().deleteDiet(widget.diet.id);
if (result)
Future.delayed(Duration(seconds: 3), () {
showBottomSheetWithBlur(
context: context,
child: Column(
children: [
SizedBox(
height: 20,
),
BottomSheetHandlerBar(),
SizedBox(
height: 20,
),
Text(
'${widget.diet.name}',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
Text(
s.deleted,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomOutlinedButton(
onPressed: () {
context.pop();
},
text: 'Хорошо',
height: 52,
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(
side: WidgetStatePropertyAll(BorderSide.none),
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
),
showBottomSheetWithBlur(
context: context,
child: Column(
children: [
SizedBox(
height: 20,
),
BottomSheetHandlerBar(),
SizedBox(
height: 20,
),
Text(
'${widget.diet.name}',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
Text(
s.deleted,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomOutlinedButton(
onPressed: () {
context.pop();
},
text: 'Хорошо',
height: 52,
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(
side: WidgetStatePropertyAll(BorderSide.none),
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
),
),
SizedBox(
height: 20,
),
],
),
);
});
),
SizedBox(
height: 20,
),
],
),
);
},
height: 52,
width: 52,