Confirm with user before clearing datastore

This commit is contained in:
Ankit Mahato
2023-05-04 14:11:39 +05:30
parent e440b5a5a7
commit 64e7e14cfa
2 changed files with 36 additions and 8 deletions

View File

@ -20,6 +20,7 @@ final kColorTransparentState =
MaterialStateProperty.all<Color>(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);

View File

@ -83,18 +83,45 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
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<String>(
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: <Widget>[
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"),
),
),