@@ -11,6 +11,7 @@ class HistorySidebarHeader extends ConsumerWidget {
11
11
@override
12
12
Widget build (BuildContext context, WidgetRef ref) {
13
13
final mobileScaffoldKey = ref.read (mobileScaffoldKeyStateProvider);
14
+ final sm = ScaffoldMessenger .of (context);
14
15
return Padding (
15
16
padding: kPe4,
16
17
child: Row (
@@ -29,53 +30,29 @@ class HistorySidebarHeader extends ConsumerWidget {
29
30
? kColorDarkDanger
30
31
: kColorLightDanger,
31
32
onPressed: () {
32
- showDialog (
33
- context: context,
34
- builder: (context) => AlertDialog (
35
- title: const Text ('Clear History' ),
36
- content: const Text (
37
- 'Are you sure you want to clear all history? This action cannot be undone.' ),
38
- actions: [
39
- TextButton (
40
- onPressed: () => Navigator .pop (context),
41
- child: const Text ('Cancel' ),
42
- ),
43
- TextButton (
44
- onPressed: () async {
45
- try {
46
- await ref
47
- .read (historyMetaStateNotifier.notifier)
48
- .clearAllHistory ();
49
-
50
- if (context.mounted) {
51
- Navigator .pop (context);
52
- ScaffoldMessenger .of (context).showSnackBar (
53
- const SnackBar (
54
- content: Text ('History cleared successfully' ),
55
- duration: Duration (seconds: 2 ),
56
- ),
57
- );
58
- }
59
- } catch (e) {
60
- if (context.mounted) {
61
- Navigator .pop (context);
62
- ScaffoldMessenger .of (context).showSnackBar (
63
- const SnackBar (
64
- content: Text ('Error clearing history' ),
65
- backgroundColor: Colors .red,
66
- duration: Duration (seconds: 2 ),
67
- ),
68
- );
69
- }
70
- }
71
- },
72
- style: TextButton .styleFrom (
73
- foregroundColor: Theme .of (context).colorScheme.error,
74
- ),
75
- child: const Text ('Clear' ),
76
- ),
77
- ],
78
- ),
33
+ showOkCancelDialog (
34
+ context,
35
+ dialogTitle: kTitleClearHistory,
36
+ content: kMsgClearHistory,
37
+ onClickOk: () async {
38
+ sm.hideCurrentSnackBar ();
39
+ try {
40
+ await ref
41
+ .read (historyMetaStateNotifier.notifier)
42
+ .clearAllHistory ();
43
+ sm.showSnackBar (getSnackBar (
44
+ kMsgClearHistorySuccess,
45
+ small: false ,
46
+ ));
47
+ } catch (e) {
48
+ debugPrint ("Clear History Stack: $e " );
49
+ sm.showSnackBar (getSnackBar (
50
+ kMsgClearHistoryError,
51
+ small: false ,
52
+ color: kColorRed,
53
+ ));
54
+ }
55
+ },
79
56
);
80
57
},
81
58
),
0 commit comments