From 64e7e14cfa73aedb86dbf6da89b837a84fef92b5 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Thu, 4 May 2023 14:11:39 +0530 Subject: [PATCH] Confirm with user before clearing datastore --- lib/consts.dart | 1 + lib/screens/settings_page.dart | 43 +++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/consts.dart b/lib/consts.dart index 9709c341..4a0bc0fe 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -20,6 +20,7 @@ final kColorTransparentState = MaterialStateProperty.all(Colors.transparent); const kColorTransparent = Colors.transparent; const kColorWhite = Colors.white; +const kColorRed = Colors.red; final kColorLightDanger = Colors.red.withOpacity(0.9); const kColorDarkDanger = Color(0xffcf6679); diff --git a/lib/screens/settings_page.dart b/lib/screens/settings_page.dart index 3f38a0fa..98f7520f 100644 --- a/lib/screens/settings_page.dart +++ b/lib/screens/settings_page.dart @@ -83,18 +83,45 @@ class _SettingsPageState extends ConsumerState { backgroundColor: settings.isDark ? kColorDarkDanger : kColorLightDanger, - surfaceTintColor: Colors.red, + surfaceTintColor: kColorRed, foregroundColor: Theme.of(context).colorScheme.onPrimary), onPressed: clearingData ? null - : () async { - await ref - .read(collectionStateNotifierProvider.notifier) - .clearData(); + : () => showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: const Text('Clear Data'), + content: const Text( + 'This action will clear all the requests data from the disk and is irreversible. Do you want to proceed?'), + actions: [ + TextButton( + onPressed: () => + Navigator.pop(context, 'Cancel'), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () async { + Navigator.pop(context, 'Yes'); + await ref + .read(collectionStateNotifierProvider + .notifier) + .clearData(); - sm.hideCurrentSnackBar(); - sm.showSnackBar(getSnackBar("Requests Data Cleared")); - }, + sm.hideCurrentSnackBar(); + sm.showSnackBar( + getSnackBar("Requests Data Cleared")); + }, + child: Text( + 'Yes', + style: kTextStyleButton.copyWith( + color: settings.isDark + ? kColorDarkDanger + : kColorLightDanger), + ), + ), + ], + ), + ), child: const Text("Clear Data"), ), ),