From 42701222296d7ade757a69e1e451a6ba2323961c Mon Sep 17 00:00:00 2001 From: Suriya Date: Thu, 23 Jul 2026 15:59:24 +0530 Subject: [PATCH] permission fixes --- android/app/src/main/AndroidManifest.xml | 1 - .../provider/profile/create_request.dart | 42 +++++ lib/view/account/account_view.dart | 157 +++++++++++++++++- 3 files changed, 198 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index da2efbb..84b5997 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ android:label="Nearle Daily" android:name="${applicationName}" android:usesCleartextTraffic="true" - android:requestLegacyExternalStorage="true" android:enableOnBackInvokedCallback="true" android:icon="@mipmap/ic_launcher"> diff --git a/lib/domain/provider/profile/create_request.dart b/lib/domain/provider/profile/create_request.dart index e416d0e..658934c 100644 --- a/lib/domain/provider/profile/create_request.dart +++ b/lib/domain/provider/profile/create_request.dart @@ -52,6 +52,48 @@ class CustomerRequestProvider with ChangeNotifier { } } + /// Submit an account deletion request (reuses the same request pipeline + /// used for support tickets, tagged so the backend/support team can + /// identify and action it as a deletion instead of general support). + Future sendAccountDeletionRequest() async { + isLoading = true; + notifyListeners(); + + SharedPreferences prefs = await SharedPreferences.getInstance(); + int? customerId = prefs.getInt('customerId'); + + if (customerId == null) { + isLoading = false; + notifyListeners(); + throw Exception("Something went wrong"); + } + + final model = CustomerRequestModel( + referencedate: DateTime.now().toUtc().toIso8601String().split('.').first + 'Z', + referencetype: "account_deletion", + customerid: customerId, + tenantid: 0, + locationid: 0, + subject: "Account Deletion Request", + remarks: "Customer has requested deletion of their account and associated data.", + status: 0, + apptypeid: 98, + ); + + final result = await _repository.createCustomerRequest(model); + + isLoading = false; + notifyListeners(); + + if (result != null && result is Map && result["status"] != false) { + debugPrint("✅ Account deletion request submitted: $result"); + return true; + } else { + debugPrint("❌ Account deletion request failed: $result"); + return false; + } + } + /// Fetch customer requests (status) Future fetchCustomerRequests({int pageNo = 1, int pageSize = 10}) async { isLoading = true; diff --git a/lib/view/account/account_view.dart b/lib/view/account/account_view.dart index 5712e21..3af7f6e 100644 --- a/lib/view/account/account_view.dart +++ b/lib/view/account/account_view.dart @@ -9,6 +9,8 @@ import 'package:nearledaily/view/authentication/login_view.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:shimmer/shimmer.dart'; +import '../../domain/provider/profile/create_request.dart'; + import '../../constants/color_constants.dart'; import '../../constants/font_constants.dart'; import '../../controllers/account_controller/profile.dart'; @@ -291,7 +293,15 @@ class _AccountPageState extends State { ), - // _divider(), + _divider(), + _tile( + icon: Icons.delete_outline, + title: "Delete Account", + isLogout: true, + onTap: () { + showDeleteAccountDialog(); + }, + ), ], ), @@ -634,6 +644,151 @@ class _AccountPageState extends State { } + /// DELETE ACCOUNT DIALOG (mirrors showLogoutDialog) + void showDeleteAccountDialog() { + Get.dialog( + Dialog( + elevation: 0, + backgroundColor: Colors.transparent, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.15), + blurRadius: 20, + offset: const Offset(0, 10), + ), + ], + ), + padding: const EdgeInsets.all(22), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + height: 64, + width: 64, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: const Icon( + Icons.delete_outline_rounded, + size: 30, + color: Colors.white, + ), + ), + + const SizedBox(height: 16), + + ReusableTextWidget( + text: "Delete Account", + fontSize: 18, + fontWeight: FontWeight.w600, + fontFamily: FontConstants.fontFamily, + color: Colors.black, + ), + + const SizedBox(height: 6), + + ReusableTextWidget( + text: + "We'll submit a request to permanently delete your account and data. This cannot be undone. Continue?", + fontSize: 14, + fontWeight: FontWeight.w400, + fontFamily: FontConstants.fontFamily, + color: Colors.black54, + textAlign: TextAlign.center, + ), + + const SizedBox(height: 24), + + Row( + children: [ + Expanded( + child: OutlinedButton( + onPressed: () => Navigator.pop(context), + style: OutlinedButton.styleFrom( + foregroundColor: primaryColor, + side: BorderSide(color: primaryColor), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + padding: const EdgeInsets.symmetric(vertical: 12), + ), + child: ReusableTextWidget( + text: "Cancel", + fontFamily: FontConstants.fontFamily, + fontWeight: FontWeight.w500, + ), + ), + ), + const SizedBox(width: 12), + Expanded( + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + elevation: 4, + padding: const EdgeInsets.symmetric(vertical: 12), + ), + onPressed: () async { + Navigator.pop(context); + + bool success = false; + try { + success = await CustomerRequestProvider() + .sendAccountDeletionRequest(); + } catch (e) { + success = false; + } + + if (!success) { + Get.snackbar( + "Error", + "Couldn't submit your deletion request. Please try again or contact support.", + ); + return; + } + + Get.snackbar( + "Request submitted", + "Your account deletion request has been received. Our team will process it shortly.", + ); + + final prefs = await SharedPreferences.getInstance(); + String fcmToken = prefs.getString('fcmToken') ?? ''; + String deviceId = + prefs.getString('currentDeviceId') ?? ''; + await prefs.clear(); + await prefs.setString('fcmToken', fcmToken); + await prefs.setString('currentDeviceId', deviceId); + + Get.deleteAll(); + GlobalBinding().dependencies(); + Get.offAll(() => Login_view()); + }, + child: ReusableTextWidget( + text: "Delete", + fontFamily: FontConstants.fontFamily, + color: Colors.white, + fontWeight: FontWeight.w600, + ), + ), + ), + ], + ), + ], + ), + ), + ), + ); + } + + Widget accountListShimmerSingleBox() { return Container( margin: const EdgeInsets.all(16),