Skip to content

Commit 99ab77c

Browse files
committed
Update onPressed dialog box
1 parent a841e57 commit 99ab77c

File tree

1 file changed

+24
-47
lines changed

1 file changed

+24
-47
lines changed

lib/screens/history/history_widgets/his_sidebar_header.dart

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class HistorySidebarHeader extends ConsumerWidget {
1111
@override
1212
Widget build(BuildContext context, WidgetRef ref) {
1313
final mobileScaffoldKey = ref.read(mobileScaffoldKeyStateProvider);
14+
final sm = ScaffoldMessenger.of(context);
1415
return Padding(
1516
padding: kPe4,
1617
child: Row(
@@ -29,53 +30,29 @@ class HistorySidebarHeader extends ConsumerWidget {
2930
? kColorDarkDanger
3031
: kColorLightDanger,
3132
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+
},
7956
);
8057
},
8158
),

0 commit comments

Comments
 (0)