| @@ -9,6 +9,7 @@ import 'package:qadirneyriz/config/config.dart'; | |||
| import 'package:qadirneyriz/screens/aboutUs/screen.dart'; | |||
| import 'package:qadirneyriz/screens/auth/state/state.dart'; | |||
| import 'package:qadirneyriz/screens/change_pass/screen.dart'; | |||
| import 'package:qadirneyriz/screens/delete_account/screen.dart'; | |||
| import 'package:qadirneyriz/screens/home/screen.dart'; | |||
| import 'package:qadirneyriz/screens/home/state.dart'; | |||
| import 'package:qadirneyriz/screens/meeting/screen.dart'; | |||
| @@ -47,6 +48,7 @@ class _CustomDrawerNavigationState extends State<CustomDrawerNavigation> { | |||
| const PrivateMeetingsScreen(), | |||
| const ReportScreen(), | |||
| const ChangePassScreen(), | |||
| const DeleteAccountScreen(), | |||
| const AboutUsScreen() | |||
| // Add more screens here | |||
| ]; | |||
| @@ -145,10 +147,16 @@ class _CustomDrawerNavigationState extends State<CustomDrawerNavigation> { | |||
| text: AppLocalizations.of(context)!.profile, | |||
| index: 4, | |||
| ), | |||
| if (userRole == 1) | |||
| _buildDrawerItem( | |||
| icon: Icons.delete_outlined, | |||
| text: AppLocalizations.of(context)!.deleteaccount, | |||
| index: 5, | |||
| ), | |||
| _buildDrawerItem( | |||
| icon: FontAwesomeIcons.info, | |||
| text: AppLocalizations.of(context)!.aboutus, | |||
| index: 5, | |||
| index: 6, | |||
| ), | |||
| ], | |||
| ), | |||
| @@ -121,5 +121,8 @@ | |||
| "profile":"User Account", "doyouredit":"You must make at least one change", | |||
| "changename":"Change Username", | |||
| "newpass":"Your New Password", | |||
| "textaboutus":"The Mizban meeting and appointment management software has been designed and developed with the aim of facilitating and optimizing the processes of organizing organizational and personal meetings under the leadership of Dr. Mohsen Mostafapour. This innovative and user-centric software serves as an efficient tool to enhance coordination and realize the motto **The Codeword of Empathy** within the esteemed **Foulad Ghadir Neyriz** organization. The Mizban project was initiated and launched with the invaluable support and backing of the esteemed CEO, Dr. Mohsen Mostafapour, representing a significant step forward in the organization's path toward growth and excellence." | |||
| "deleteaccount": "Delete Account", | |||
| "suretodelelteaccount": "Are you sure you want to delete your account?", | |||
| "actioncantundo": "This action cannot be undone!", | |||
| "textaboutus":"The Mizban meeting and appointment management software has been designed and developed with the aim of facilitating and optimizing the processes of organizing organizational and personal meetings under the leadership of Dr. Mohsen Mostafapour. This innovative and user-centric software serves as an efficient tool to enhance coordination and realize the motto **The Codeword of Empathy** within the esteemed **Foulad Ghadir Neyriz** organization. The Mizban project was initiated and launched with the invaluable support and backing of the esteemed CEO, Dr. Mohsen Mostafapour, representing a significant step forward in the organization's path toward growth and excellence." | |||
| } | |||
| @@ -118,7 +118,9 @@ | |||
| "profile":"حساب کاربری", | |||
| "doyouredit":"باید حداقل یکی از تغییرات را انجام دهید!", | |||
| "changename":"تغییر نام کاربری", | |||
| "newpass":"رمزعبور جدید شما", | |||
| "newpass":"رمزعبور جدید شما", "deleteaccount": "پاک کردن حساب کاربری", | |||
| "suretodelelteaccount": "آیا اطمینان دارید که میخواهید حساب کاربری خود را حذف کنید؟", | |||
| "actioncantundo": "این عمل قابل بازگشت نیست!", | |||
| "areusuretodeletfile":"آیا اطمینان دارید که میخواهید این فایل را حذف کنید؟", | |||
| "textaboutus":"نرمافزار مدیریت جلسات و ملاقاتهای “میزبان” با هدف تسهیل و بهینهسازی فرآیندهای برگزاری جلسات سازمانی و شخصی جناب آقای دکتر محسن مصطفی پور طراحی و توسعه یافته تا ابزاری کارآمد و نوآورانه برای تحقق بیشتر اسم رمز همدلی در مجموعه معظم فولاد غدیر نی ریز باشد . این نرم افزار با حمایت ، همت و پشتیبانی بیدریغ مدیریت محترم عامل ( دکتر محسن مصطفی پور ) ایجاد ، توسعه و راه اندازی شده است." | |||
| } | |||
| @@ -47,6 +47,7 @@ final GoRouter router = GoRouter( | |||
| ), | |||
| GoRoute( | |||
| path: '/route', | |||
| name: 'route', | |||
| builder: (BuildContext context, GoRouterState state) { | |||
| return const SplashScreen(); | |||
| }, | |||
| @@ -0,0 +1,101 @@ | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:go_router/go_router.dart'; | |||
| import 'package:provider/provider.dart'; | |||
| import 'package:qadirneyriz/screens/home/state.dart'; | |||
| import 'package:qadirneyriz/setting/setting.dart'; | |||
| import 'package:qadirneyriz/utils/enums/status.dart'; | |||
| import 'package:qadirneyriz/utils/tools/tools.dart'; | |||
| import 'package:qadirneyriz/widgets/custom_appbar.dart'; | |||
| import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | |||
| import 'package:qadirneyriz/widgets/custom_button.dart'; | |||
| class DeleteAccountScreen extends StatefulWidget { | |||
| const DeleteAccountScreen({super.key}); | |||
| @override | |||
| State<DeleteAccountScreen> createState() => _DeleteAccountScreenState(); | |||
| } | |||
| class _DeleteAccountScreenState extends State<DeleteAccountScreen> { | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return Consumer<HomeState>( | |||
| builder: (context, value, child) { | |||
| return CustomScrollView( | |||
| slivers: [ | |||
| CustomAppbar(), | |||
| SliverFillRemaining( | |||
| hasScrollBody: false, | |||
| child: Padding( | |||
| padding: const EdgeInsets.all(16.0), | |||
| child: Column( | |||
| children: [ | |||
| const Icon( | |||
| Icons.warning_amber_rounded, | |||
| size: 100, | |||
| color: Colors.red, | |||
| ), | |||
| const SizedBox(height: 20), | |||
| Text( | |||
| AppLocalizations.of(context)!.suretodelelteaccount, | |||
| textAlign: TextAlign.center, | |||
| style: | |||
| TextStyle(fontSize: 18, fontWeight: FontWeight.bold), | |||
| ), | |||
| const SizedBox(height: 20), | |||
| Text( | |||
| AppLocalizations.of(context)!.actioncantundo, | |||
| textAlign: TextAlign.center, | |||
| style: TextStyle(fontSize: 16, color: Colors.grey[600]), | |||
| ), | |||
| const SizedBox(height: 40), | |||
| deleteButton(value), | |||
| ], | |||
| ), | |||
| ), | |||
| ), | |||
| ], | |||
| ); | |||
| }, | |||
| ); | |||
| } | |||
| CustomButton deleteButton(HomeState state) { | |||
| switch (state.statusDeleteAccount) { | |||
| case Status.loading: | |||
| return CustomButton( | |||
| onPressed: null, | |||
| text: AppLocalizations.of(context)!.loading, | |||
| hieght: 50, | |||
| ); | |||
| default: | |||
| return CustomButton( | |||
| onPressed: () async { | |||
| final status = await state.deleteAccount(); | |||
| if (status == Status.ready) { | |||
| final logOut = await setting.userLocalDb.logOut(); | |||
| if (logOut) { | |||
| context.goNamed('route'); | |||
| Tools.showCustomSnackBar(context, | |||
| text: state.messageDeleteAccount ?? 'Done successfully', | |||
| isError: false); | |||
| } else { | |||
| Tools.showCustomSnackBar(context, | |||
| text: state.messageDeleteAccount ?? | |||
| AppLocalizations.of(context)!.error, | |||
| isError: true); | |||
| } | |||
| } else { | |||
| Tools.showCustomSnackBar(context, | |||
| text: state.messageDeleteAccount ?? | |||
| AppLocalizations.of(context)!.error, | |||
| isError: true); | |||
| } | |||
| }, | |||
| text: AppLocalizations.of(context)!.deleteaccount, | |||
| hieght: 50, | |||
| ); | |||
| } | |||
| } | |||
| } | |||
| @@ -435,11 +435,18 @@ class _HomeScreenState extends State<HomeScreen> { | |||
| AppLocalizations.of(context)!.error, | |||
| isError: true); | |||
| } else if (status == Status.ready) { | |||
| setting.userLocalDb.logOut(); | |||
| context.pushReplacementNamed('login'); | |||
| Tools.showCustomSnackBar(context, | |||
| text: value.messageLogOut ?? 'Done successfully', | |||
| isError: false); | |||
| final logOut = await setting.userLocalDb.logOut(); | |||
| if (logOut) { | |||
| context.goNamed('login'); | |||
| Tools.showCustomSnackBar(context, | |||
| text: value.messageLogOut ?? 'Done successfully', | |||
| isError: false); | |||
| } else { | |||
| Tools.showCustomSnackBar(context, | |||
| text: value.messageLogOut ?? | |||
| AppLocalizations.of(context)!.error, | |||
| isError: true); | |||
| } | |||
| } | |||
| }, | |||
| ), | |||
| @@ -80,6 +80,40 @@ class HomeState extends ChangeNotifier { | |||
| return statusLogOut; | |||
| } | |||
| // delete account | |||
| Status statusDeleteAccount = Status.empty; | |||
| String? messageDeleteAccount; | |||
| Map? errorsDeleteAccount; | |||
| Future<Status> deleteAccount() async { | |||
| statusDeleteAccount = Status.loading; | |||
| notifyListeners(); | |||
| try { | |||
| final result = await homeApi.deleteAccountApi(); | |||
| if (result == null) { | |||
| statusDeleteAccount = Status.error; | |||
| } else { | |||
| if (result.isOk) { | |||
| statusDeleteAccount = Status.ready; | |||
| messageDeleteAccount = result.message; | |||
| } else if (result.isOk == false) { | |||
| errorsDeleteAccount = result.errors; | |||
| messageDeleteAccount = result.message; | |||
| statusDeleteAccount = Status.error; | |||
| } else { | |||
| statusDeleteAccount = Status.error; | |||
| } | |||
| } | |||
| notifyListeners(); | |||
| } catch (e) { | |||
| statusDeleteAccount = Status.error; | |||
| // print(e); | |||
| } | |||
| notifyListeners(); | |||
| // print(statusLogOut); | |||
| return statusDeleteAccount; | |||
| } | |||
| // edit profile | |||
| Status statusEditProfile = Status.empty; | |||
| String? messageEditProfile; | |||
| @@ -53,6 +53,35 @@ class HomeApi { | |||
| return const Result(isOk: false); | |||
| } | |||
| // delete account | |||
| Future<Result?> deleteAccountApi() async { | |||
| try { | |||
| Map<String, String> headers = {"Accept": "application/json"}; | |||
| String dataToken = setting.userLocalDb.getUser().token!; | |||
| if (dataToken != '') { | |||
| headers['Authorization'] = "Bearer $dataToken"; | |||
| } | |||
| final res = await Dio().post( | |||
| "${config.network.baseUrl}user/deleteaccount", | |||
| options: Options(headers: headers)); | |||
| if (res.statusCode == 200 || res.statusCode == 201) { | |||
| setting.userLocalDb.logOut(); | |||
| return const Result(isOk: true); | |||
| } | |||
| } on DioException catch (e) { | |||
| // print(e); | |||
| // print(e.response!.data); | |||
| return Result( | |||
| isOk: false, | |||
| errors: e.response!.data['errors'], | |||
| message: e.response!.data['message']); | |||
| } | |||
| return const Result(isOk: false); | |||
| } | |||
| // edit profile | |||
| Future<Result?> editProfile({String? name, String? password}) async { | |||
| @@ -2,6 +2,7 @@ import 'dart:io'; | |||
| import 'package:flutter/foundation.dart'; | |||
| import 'package:hive/hive.dart'; | |||
| import 'package:path_provider/path_provider.dart'; | |||
| import 'package:qadirneyriz/utils/enums/status.dart'; | |||
| import 'package:qadirneyriz/utils/hive/local_user.dart'; | |||
| class UserLocalDb { | |||
| @@ -56,10 +57,15 @@ class UserLocalDb { | |||
| await box!.put(key, value); | |||
| } | |||
| void logOut() async { | |||
| await openBox(); | |||
| await box!.clear(); // حذف تمامی دادهها از داخل box | |||
| // Navigate to login screen | |||
| Future<bool> logOut() async { | |||
| await openBox(); // باز کردن Box | |||
| await box!.clear(); // حذف تمامی دادهها از Box | |||
| // بررسی تعداد آیتمهای باقیمانده | |||
| final int remainingItems = box!.length; | |||
| // بازگرداندن true اگر دادهها حذف شدند، false در غیر این صورت | |||
| return remainingItems == 0; | |||
| } | |||
| // Future<void> updateUser(LocalUser user) async { | |||