Skip to content

Commit 9025435

Browse files
authored
Merge pull request #569 from nope3472/resolve-issue-history-clear
Resolved Issue #562
2 parents b54074a + cd84788 commit 9025435

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed

lib/consts.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,9 @@ const kMsgNoContent = "No content";
473473
const kMsgUnknowContentType = "Unknown Response Content-Type";
474474
// Workspace Selector
475475
const kMsgSelectWorkspace = "Create your workspace";
476+
// History Page
477+
const kTitleClearHistory = 'Clear History';
478+
const kMsgClearHistory =
479+
'Clearing History is permanent. Do you want to continue?';
480+
const kMsgClearHistorySuccess = 'History cleared successfully';
481+
const kMsgClearHistoryError = 'Error clearing history';

lib/screens/history/history_widgets/his_sidebar_header.dart

Lines changed: 24 additions & 4 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(
@@ -28,10 +29,29 @@ class HistorySidebarHeader extends ConsumerWidget {
2829
color: Theme.of(context).brightness == Brightness.dark
2930
? kColorDarkDanger
3031
: kColorLightDanger,
31-
onPressed: () async {
32-
await ref
33-
.read(historyMetaStateNotifier.notifier)
34-
.clearAllHistory();
32+
onPressed: () {
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+
));
46+
} catch (e) {
47+
debugPrint("Clear History Stack: $e");
48+
sm.showSnackBar(getSnackBar(
49+
kMsgClearHistoryError,
50+
color: kColorRed,
51+
));
52+
}
53+
},
54+
);
3555
},
3656
),
3757
ADIconButton(

lib/widgets/dialog_ok_cancel.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'package:apidash/consts.dart';
2+
import 'package:apidash_design_system/apidash_design_system.dart';
3+
import 'package:flutter/material.dart';
4+
5+
showOkCancelDialog(
6+
BuildContext context, {
7+
String? dialogTitle,
8+
String? content,
9+
String? buttonLabelOk,
10+
VoidCallback? onClickOk,
11+
String? buttonLabelCancel,
12+
VoidCallback? onClickCancel,
13+
}) {
14+
showDialog(
15+
context: context,
16+
builder: (context) {
17+
return AlertDialog(
18+
title: Text(dialogTitle ?? ""),
19+
titleTextStyle: Theme.of(context).textTheme.titleLarge,
20+
content: Container(
21+
padding: kPt20,
22+
width: 300,
23+
child: Text(content ?? ""),
24+
),
25+
actions: <Widget>[
26+
TextButton(
27+
onPressed: () {
28+
onClickCancel?.call();
29+
if (context.mounted) {
30+
Navigator.pop(context);
31+
}
32+
},
33+
child: Text(buttonLabelCancel ?? kLabelCancel),
34+
),
35+
TextButton(
36+
onPressed: () {
37+
onClickOk?.call();
38+
if (context.mounted) {
39+
Navigator.pop(context);
40+
}
41+
},
42+
child: Text(buttonLabelOk ?? kLabelOk),
43+
),
44+
],
45+
);
46+
});
47+
}

lib/widgets/widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export 'codegen_previewer.dart';
1616
export 'dialog_about.dart';
1717
export 'dialog_history_retention.dart';
1818
export 'dialog_import.dart';
19+
export 'dialog_ok_cancel.dart';
1920
export 'dialog_rename.dart';
2021
export 'dialog_text.dart';
2122
export 'drag_and_drop_area.dart';

packages/apidash_design_system/lib/widgets/snackbar.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
33
SnackBar getSnackBar(
44
String text, {
55
bool small = true,
6+
Color? color,
67
}) {
78
return SnackBar(
89
width: small ? 300 : 500,
10+
backgroundColor: color,
911
behavior: SnackBarBehavior.floating,
1012
content: Text(
1113
text,

0 commit comments

Comments
 (0)