Skip to content

Commit

Permalink
Fix: #307 - Delete wallet implementation from developer options
Browse files Browse the repository at this point in the history
  • Loading branch information
lijogeorgep authored and josmilan committed Apr 23, 2024
1 parent 6090f68 commit 55b8481
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:Data4Diabetes/app/core/base/base_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../launcher/views/launcher_view.dart';
import '../views/dexcom_credential_view.dart';
import '../views/privacy_dashboard_credential_view.dart';

Expand All @@ -12,4 +16,21 @@ Get.to(PrivacyDashboardCredentialView());
setDexcomCred(){
Get.to(DexcomCredentialView());
}
deleteWallet() async {
// delete wallet
var platform = const MethodChannel('io.igrant.data4diabetes.channel');
platform.invokeMethod('DeleteWallet');
Get.rawSnackbar(
message: "Wallet deleted successfully",
backgroundColor: Colors.green);
SharedPreferences _prefs = await SharedPreferences.getInstance();
Set<String> keys = _prefs.getKeys();

for (String key in keys) {
if (key != 'languageCode') {
await _prefs.remove(key);
}
}
Get.offAll(const LauncherView());
}
}
48 changes: 48 additions & 0 deletions lib/app/modules/developerOptions/views/credentials_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/preferred_size.dart';
import 'package:get/get.dart';
Expand All @@ -8,6 +10,7 @@ import '../../../Constants/Palette.dart';
import '../../../core/base/base_view.dart';
import '../../../core/values/app_colors.dart';
import '../../../core/widget/app_bar_title.dart';
import '../../launcher/views/launcher_view.dart';
import '../controllers/credentials_controller.dart';

class CredentailsView extends BaseView<CredentialsController> {
Expand Down Expand Up @@ -52,6 +55,8 @@ class CredentailsView extends BaseView<CredentialsController> {
_privacyDashboardCredWidget(),
const Divider(),
_dexcomCredWidget(),
const Divider(),
_deleteWallet(context),
],
),
),
Expand Down Expand Up @@ -112,4 +117,47 @@ class CredentailsView extends BaseView<CredentialsController> {
);

}

_deleteWallet(BuildContext context) {
return ListTile(
dense: true,
visualDensity: const VisualDensity(horizontal: 0, vertical: -3),
title: const Text(
'Delete Wallet',
style: TextStyle(
fontSize: 14,
),
),
trailing: const Icon(
Icons.arrow_forward_ios,
size: 15.0,
),
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: const Text("Alert"),
content: const Text("Do you want to delete your wallet?"),
actions: [
CupertinoDialogAction(
child: const Text("Yes"),
onPressed: () {
_credentialsController.deleteWallet();

},
),
CupertinoDialogAction(
child: const Text("No"),
onPressed: () {
Get.back();
},
),
],
);
},
);
},
);
}
}
4 changes: 0 additions & 4 deletions lib/app/modules/settings/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class SettingsController extends BaseController {
await _prefs.remove(key);
}
}
//delete wallet
platform.invokeMethod('DeleteWallet');
Get.offAll(const LauncherView());
}

Expand All @@ -72,8 +70,6 @@ class SettingsController extends BaseController {
color: Colors.green);
SharedPreferences _prefs = await SharedPreferences.getInstance();
_prefs.clear();
// delete wallet
platform.invokeMethod('DeleteWallet');
Get.offAll(const LauncherView());
} else {
GetSnackToast(message: appLocalization.settingsDeleteAccountFail);
Expand Down

0 comments on commit 55b8481

Please sign in to comment.