feat(setting): added account deleting

This commit is contained in:
Username1548
2025-07-16 19:30:30 +07:00
parent 74fa65a1ba
commit 773359e900
8 changed files with 174 additions and 5 deletions

View File

@@ -228,7 +228,7 @@ class AppRouter {
return '/auth-screen';
}
} catch (e) {
rethrow;
return '/feed-screen';
}
},
),

View File

@@ -203,4 +203,12 @@ class ProfileRepository {
return false;
}
}
Future<void> deleteAccount() async {
try {
await profileService.deleteAccount();
} catch (e) {
rethrow;
}
}
}

View File

@@ -119,4 +119,7 @@ abstract class ProfileService {
Future<void> tryVerifyEmailByCode({
@Body() required String code,
});
@DELETE('/api/profile/delete_my_account')
Future<void> deleteAccount();
}

View File

@@ -67,4 +67,13 @@ class SettingsCubit extends Cubit<SettingsState> {
await init();
}
}
Future<bool> deleteAccount() async {
try {
await profileRepository.deleteAccount();
return true;
} catch (e) {
return false;
}
}
}

View File

@@ -1,12 +1,19 @@
import 'package:eatvio_app/core/app_router.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
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/data_error_widget.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/core/widgets/show_error_dialog.dart';
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -60,7 +67,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_aboutEatvio(state),
const SizedBox(height: 12),
_becomeConsultantButton(state),
_deleteAccountButton(state),
_deleteAccountButton(state, settingsCubit),
],
),
),
@@ -428,11 +435,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
return const SizedBox.shrink();
}
Padding _deleteAccountButton(SettingsStateLoaded state) {
Padding _deleteAccountButton(SettingsStateLoaded state, SettingsCubit settingsCubit) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: InkWell(
onTap: () {},
onTap: () async {
showBottomSheetWithBlur(
userRootNavigator: true,
context: context,
height: null,
child: DeleteAccountBottomSheet(
cubit: settingsCubit,
),
);
},
borderRadius: BorderRadius.circular(20),
child: Ink(
height: 52,
@@ -495,3 +511,73 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
}
class DeleteAccountBottomSheet extends StatefulWidget {
const DeleteAccountBottomSheet({super.key, required this.cubit});
final SettingsCubit cubit;
@override
State<DeleteAccountBottomSheet> createState() => _DeleteAccountBottomSheet();
}
class _DeleteAccountBottomSheet extends State<DeleteAccountBottomSheet> {
bool? isFailure;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(
height: 8,
),
const BottomSheetHandlerBar(),
const SizedBox(
height: 20,
),
Text(s.accountDeleting, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)),
const SizedBox(
height: 16,
),
Text(
s.youShureYouWantToDeleteAccount,
style: TextStyles.textSMedium.copyWith(color: appTheme.black),
textAlign: TextAlign.center,
),
const SizedBox(
height: 8,
),
Text(
s.itCantBeRecovered,
style: TextStyles.textSMedium.copyWith(color: appTheme.black),
textAlign: TextAlign.center,
),
const SizedBox(
height: 8,
),
CustomOutlinedButton(
text: s.delete,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () async {
final result = await widget.cubit.deleteAccount();
if (result == true) {
AppRouter.navigatorKey.currentContext?.go('/auth-screen');
return;
}
AppRouter.navigatorKey.currentContext?.pop();
if (!context.mounted) return;
showErrorDialog(context, description: s.cannotDeleteAccount);
},
),
const SizedBox(
height: 40,
),
],
),
);
}
}

View File

@@ -51,6 +51,9 @@ class MessageLookup extends MessageLookupByLibrary {
"about_diet": MessageLookupByLibrary.simpleMessage("Об этой диете"),
"about_plan": MessageLookupByLibrary.simpleMessage("Об этом плане"),
"about_recipe": MessageLookupByLibrary.simpleMessage("Об этом рецепте"),
"accountDeleting": MessageLookupByLibrary.simpleMessage(
"Удаление аккаунта",
),
"active": MessageLookupByLibrary.simpleMessage("Активен"),
"active_consultations_count": MessageLookupByLibrary.simpleMessage(
"Кол-во активных консультаций",
@@ -124,6 +127,9 @@ class MessageLookup extends MessageLookupByLibrary {
),
"cancel_diet": MessageLookupByLibrary.simpleMessage("Отменить диету?"),
"cancel_order": MessageLookupByLibrary.simpleMessage("Отменить заказ"),
"cannotDeleteAccount": MessageLookupByLibrary.simpleMessage(
"Не получилось удалить ваш аккаунт",
),
"carb_type": MessageLookupByLibrary.simpleMessage("Мучное"),
"carb_type_desc": MessageLookupByLibrary.simpleMessage(
"Если вы любите мучные продукты, но хотите придерживаться диеты, вам подходит диета с добавленим мучных блюд на основе цельнозерновых вариантов. В них больше сложных углеводов и клетчатки, что способствует длительному чувству сытости и поддерживает здоровье пищеварительной системы.",
@@ -256,6 +262,7 @@ class MessageLookup extends MessageLookupByLibrary {
),
"days": MessageLookupByLibrary.simpleMessage("дней"),
"deception": MessageLookupByLibrary.simpleMessage("Обман"),
"delete": MessageLookupByLibrary.simpleMessage("Удалить"),
"deleteComment": MessageLookupByLibrary.simpleMessage(
"Удалить комментарий",
),
@@ -411,6 +418,9 @@ class MessageLookup extends MessageLookupByLibrary {
"invited_people_count": MessageLookupByLibrary.simpleMessage(
"Количество приглашенных",
),
"itCantBeRecovered": MessageLookupByLibrary.simpleMessage(
"Его нельзя будет восстановить",
),
"label": MessageLookupByLibrary.simpleMessage("Название"),
"language": MessageLookupByLibrary.simpleMessage("Язык"),
"last_name": MessageLookupByLibrary.simpleMessage("Фамилия"),
@@ -780,6 +790,9 @@ class MessageLookup extends MessageLookupByLibrary {
"youShureYouWantToCancelOrder": MessageLookupByLibrary.simpleMessage(
"Вы уверены, что хотите отменить заказ?",
),
"youShureYouWantToDeleteAccount": MessageLookupByLibrary.simpleMessage(
"Вы уверены, что хотите удалить аккаунт?",
),
"you_can_not_open_this_day": MessageLookupByLibrary.simpleMessage(
"Вы не можете перейти в этот день",
),

View File

@@ -3414,6 +3414,51 @@ class S {
args: [],
);
}
/// `Удаление аккаунта`
String get accountDeleting {
return Intl.message(
'Удаление аккаунта',
name: 'accountDeleting',
desc: '',
args: [],
);
}
/// `Вы уверены, что хотите удалить аккаунт?`
String get youShureYouWantToDeleteAccount {
return Intl.message(
'Вы уверены, что хотите удалить аккаунт?',
name: 'youShureYouWantToDeleteAccount',
desc: '',
args: [],
);
}
/// `Его нельзя будет восстановить`
String get itCantBeRecovered {
return Intl.message(
'Его нельзя будет восстановить',
name: 'itCantBeRecovered',
desc: '',
args: [],
);
}
/// `Удалить`
String get delete {
return Intl.message('Удалить', name: 'delete', desc: '', args: []);
}
/// `Не получилось удалить ваш аккаунт`
String get cannotDeleteAccount {
return Intl.message(
'Не получилось удалить ваш аккаунт',
name: 'cannotDeleteAccount',
desc: '',
args: [],
);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View File

@@ -405,7 +405,12 @@
"allowAccess": "Разрешить доступ" ,
"copy": "Скопировать",
"reply": "Ответить",
"deleteComment": "Удалить комментарий"
"deleteComment": "Удалить комментарий",
"accountDeleting": "Удаление аккаунта",
"youShureYouWantToDeleteAccount": "Вы уверены, что хотите удалить аккаунт?",
"itCantBeRecovered": "Его нельзя будет восстановить",
"delete": "Удалить",
"cannotDeleteAccount": "Не получилось удалить ваш аккаунт"
}