amin 1 год назад
Родитель
Сommit
b26948527e
9 измененных файлов: 203 добавлений и 12 удалений
  1. +9
    -1
      lib/drawer_navigation_bar.dart
  2. +4
    -1
      lib/l10n/app_en.arb
  3. +3
    -1
      lib/l10n/app_fa.arb
  4. +1
    -0
      lib/router/router.dart
  5. +101
    -0
      lib/screens/delete_account/screen.dart
  6. +12
    -5
      lib/screens/home/screen.dart
  7. +34
    -0
      lib/screens/home/state.dart
  8. +29
    -0
      lib/services/home/home.dart
  9. +10
    -4
      lib/utils/hive/user_local_db.dart

+ 9
- 1
lib/drawer_navigation_bar.dart Просмотреть файл

@@ -9,6 +9,7 @@ import 'package:qadirneyriz/config/config.dart';
import 'package:qadirneyriz/screens/aboutUs/screen.dart'; import 'package:qadirneyriz/screens/aboutUs/screen.dart';
import 'package:qadirneyriz/screens/auth/state/state.dart'; import 'package:qadirneyriz/screens/auth/state/state.dart';
import 'package:qadirneyriz/screens/change_pass/screen.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/screen.dart';
import 'package:qadirneyriz/screens/home/state.dart'; import 'package:qadirneyriz/screens/home/state.dart';
import 'package:qadirneyriz/screens/meeting/screen.dart'; import 'package:qadirneyriz/screens/meeting/screen.dart';
@@ -47,6 +48,7 @@ class _CustomDrawerNavigationState extends State<CustomDrawerNavigation> {
const PrivateMeetingsScreen(), const PrivateMeetingsScreen(),
const ReportScreen(), const ReportScreen(),
const ChangePassScreen(), const ChangePassScreen(),
const DeleteAccountScreen(),
const AboutUsScreen() const AboutUsScreen()
// Add more screens here // Add more screens here
]; ];
@@ -145,10 +147,16 @@ class _CustomDrawerNavigationState extends State<CustomDrawerNavigation> {
text: AppLocalizations.of(context)!.profile, text: AppLocalizations.of(context)!.profile,
index: 4, index: 4,
), ),
if (userRole == 1)
_buildDrawerItem(
icon: Icons.delete_outlined,
text: AppLocalizations.of(context)!.deleteaccount,
index: 5,
),
_buildDrawerItem( _buildDrawerItem(
icon: FontAwesomeIcons.info, icon: FontAwesomeIcons.info,
text: AppLocalizations.of(context)!.aboutus, text: AppLocalizations.of(context)!.aboutus,
index: 5,
index: 6,
), ),
], ],
), ),


+ 4
- 1
lib/l10n/app_en.arb Просмотреть файл

@@ -121,5 +121,8 @@
"profile":"User Account", "doyouredit":"You must make at least one change", "profile":"User Account", "doyouredit":"You must make at least one change",
"changename":"Change Username", "changename":"Change Username",
"newpass":"Your New Password", "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."
} }

+ 3
- 1
lib/l10n/app_fa.arb Просмотреть файл

@@ -118,7 +118,9 @@
"profile":"حساب کاربری", "profile":"حساب کاربری",
"doyouredit":"باید حداقل یکی از تغییرات را انجام دهید!", "doyouredit":"باید حداقل یکی از تغییرات را انجام دهید!",
"changename":"تغییر نام کاربری", "changename":"تغییر نام کاربری",
"newpass":"رمزعبور جدید شما",
"newpass":"رمزعبور جدید شما", "deleteaccount": "پاک کردن حساب کاربری",
"suretodelelteaccount": "آیا اطمینان دارید که می‌خواهید حساب کاربری خود را حذف کنید؟",
"actioncantundo": "این عمل قابل بازگشت نیست!",
"areusuretodeletfile":"آیا اطمینان دارید که میخواهید این فایل را حذف کنید؟", "areusuretodeletfile":"آیا اطمینان دارید که میخواهید این فایل را حذف کنید؟",
"textaboutus":"نرم‌افزار مدیریت جلسات و ملاقات‌های “میزبان” با هدف تسهیل و بهینه‌سازی فرآیندهای برگزاری جلسات سازمانی و شخصی جناب آقای دکتر محسن مصطفی پور طراحی و توسعه یافته تا ابزاری کارآمد و نوآورانه برای تحقق بیشتر اسم رمز همدلی در مجموعه معظم فولاد غدیر نی ریز باشد . این نرم افزار با حمایت ، همت و پشتیبانی بی‌دریغ مدیریت محترم عامل ( دکتر محسن مصطفی پور ) ایجاد ، توسعه و راه اندازی شده است." "textaboutus":"نرم‌افزار مدیریت جلسات و ملاقات‌های “میزبان” با هدف تسهیل و بهینه‌سازی فرآیندهای برگزاری جلسات سازمانی و شخصی جناب آقای دکتر محسن مصطفی پور طراحی و توسعه یافته تا ابزاری کارآمد و نوآورانه برای تحقق بیشتر اسم رمز همدلی در مجموعه معظم فولاد غدیر نی ریز باشد . این نرم افزار با حمایت ، همت و پشتیبانی بی‌دریغ مدیریت محترم عامل ( دکتر محسن مصطفی پور ) ایجاد ، توسعه و راه اندازی شده است."
} }

+ 1
- 0
lib/router/router.dart Просмотреть файл

@@ -47,6 +47,7 @@ final GoRouter router = GoRouter(
), ),
GoRoute( GoRoute(
path: '/route', path: '/route',
name: 'route',
builder: (BuildContext context, GoRouterState state) { builder: (BuildContext context, GoRouterState state) {
return const SplashScreen(); return const SplashScreen();
}, },


+ 101
- 0
lib/screens/delete_account/screen.dart Просмотреть файл

@@ -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,
);
}
}
}

+ 12
- 5
lib/screens/home/screen.dart Просмотреть файл

@@ -435,11 +435,18 @@ class _HomeScreenState extends State<HomeScreen> {
AppLocalizations.of(context)!.error, AppLocalizations.of(context)!.error,
isError: true); isError: true);
} else if (status == Status.ready) { } 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);
}
} }
}, },
), ),


+ 34
- 0
lib/screens/home/state.dart Просмотреть файл

@@ -80,6 +80,40 @@ class HomeState extends ChangeNotifier {
return statusLogOut; 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 // edit profile
Status statusEditProfile = Status.empty; Status statusEditProfile = Status.empty;
String? messageEditProfile; String? messageEditProfile;


+ 29
- 0
lib/services/home/home.dart Просмотреть файл

@@ -53,6 +53,35 @@ class HomeApi {
return const Result(isOk: false); 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 // edit profile


Future<Result?> editProfile({String? name, String? password}) async { Future<Result?> editProfile({String? name, String? password}) async {


+ 10
- 4
lib/utils/hive/user_local_db.dart Просмотреть файл

@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:qadirneyriz/utils/enums/status.dart';
import 'package:qadirneyriz/utils/hive/local_user.dart'; import 'package:qadirneyriz/utils/hive/local_user.dart';


class UserLocalDb { class UserLocalDb {
@@ -56,10 +57,15 @@ class UserLocalDb {
await box!.put(key, value); 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 { // Future<void> updateUser(LocalUser user) async {


Загрузка…
Отмена
Сохранить