Skip to content

Commit

Permalink
Add clear local storage button to settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Nov 12, 2023
1 parent aa891d2 commit 02b93a8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/src/settings/views/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:excode/src/settings/providers/theme_provider.dart';
import 'package:excode/src/settings/services/update_service.dart';
import 'package:excode/src/settings/widgets/about_dialog.dart';
import 'package:excode/src/settings/widgets/auth_dropdown.dart';
import 'package:excode/src/settings/widgets/clear_dialog.dart';
import 'package:excode/src/settings/widgets/dropdown_button.dart';
import 'package:excode/src/settings/widgets/font_size_button.dart';
import 'package:excode/src/settings/widgets/update_dialog.dart';
Expand Down Expand Up @@ -268,6 +269,22 @@ class SettingsView extends HookConsumerWidget {
'About and Credits',
style: TextStyle(fontSize: 16),
),
),
const Gap(10),
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return const ClearDialogWidget();
},
);
},
style: TextButton.styleFrom(minimumSize: const Size(0, 50)),
child: const Text(
'Clear local storage',
style: TextStyle(fontSize: 16),
),
)
],
),
Expand Down
36 changes: 36 additions & 0 deletions lib/src/settings/widgets/clear_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:excode/src/factory.dart';
import 'package:flutter/material.dart';

class ClearDialogWidget extends StatelessWidget {
const ClearDialogWidget({super.key});

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Clear local storage'),
content: const Text(
'This clears all the settings and code stored locally and reverts the app to defaults when reopened.\nAre you sure you want to do this?'),
actions: [
ElevatedButton(
onPressed: () async {
try {
await box.deleteFromDisk();
} finally {
if (context.mounted) {
Navigator.of(context).pop();
}
}
},
child: const Text('Confirm')),
ElevatedButton(
onPressed: () {
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text('Cancel'),
)
],
);
}
}

0 comments on commit 02b93a8

Please sign in to comment.