Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved Issue #562 #569

Merged
merged 12 commits into from
Feb 16, 2025
6 changes: 6 additions & 0 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,9 @@ const kMsgNoContent = "No content";
const kMsgUnknowContentType = "Unknown Response Content-Type";
// Workspace Selector
const kMsgSelectWorkspace = "Create your workspace";
// History Page
const kTitleClearHistory = 'Clear History';
const kMsgClearHistory =
'Clearing History is permanent. Do you want to continue?';
const kMsgClearHistorySuccess = 'History cleared successfully';
const kMsgClearHistoryError = 'Error clearing history';
28 changes: 24 additions & 4 deletions lib/screens/history/history_widgets/his_sidebar_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HistorySidebarHeader extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final mobileScaffoldKey = ref.read(mobileScaffoldKeyStateProvider);
final sm = ScaffoldMessenger.of(context);
return Padding(
padding: kPe4,
child: Row(
Expand All @@ -28,10 +29,29 @@ class HistorySidebarHeader extends ConsumerWidget {
color: Theme.of(context).brightness == Brightness.dark
? kColorDarkDanger
: kColorLightDanger,
onPressed: () async {
await ref
.read(historyMetaStateNotifier.notifier)
.clearAllHistory();
onPressed: () {
showOkCancelDialog(
context,
dialogTitle: kTitleClearHistory,
content: kMsgClearHistory,
onClickOk: () async {
sm.hideCurrentSnackBar();
try {
await ref
.read(historyMetaStateNotifier.notifier)
.clearAllHistory();
sm.showSnackBar(getSnackBar(
kMsgClearHistorySuccess,
));
} catch (e) {
debugPrint("Clear History Stack: $e");
sm.showSnackBar(getSnackBar(
kMsgClearHistoryError,
color: kColorRed,
));
}
},
);
},
),
ADIconButton(
Expand Down
47 changes: 47 additions & 0 deletions lib/widgets/dialog_ok_cancel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:apidash/consts.dart';
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart';

showOkCancelDialog(
BuildContext context, {
String? dialogTitle,
String? content,
String? buttonLabelOk,
VoidCallback? onClickOk,
String? buttonLabelCancel,
VoidCallback? onClickCancel,
}) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(dialogTitle ?? ""),
titleTextStyle: Theme.of(context).textTheme.titleLarge,
content: Container(
padding: kPt20,
width: 300,
child: Text(content ?? ""),
),
actions: <Widget>[
TextButton(
onPressed: () {
onClickCancel?.call();
if (context.mounted) {
Navigator.pop(context);
}
},
child: Text(buttonLabelCancel ?? kLabelCancel),
),
TextButton(
onPressed: () {
onClickOk?.call();
if (context.mounted) {
Navigator.pop(context);
}
},
child: Text(buttonLabelOk ?? kLabelOk),
),
],
);
});
}
1 change: 1 addition & 0 deletions lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export 'codegen_previewer.dart';
export 'dialog_about.dart';
export 'dialog_history_retention.dart';
export 'dialog_import.dart';
export 'dialog_ok_cancel.dart';
export 'dialog_rename.dart';
export 'dialog_text.dart';
export 'drag_and_drop_area.dart';
Expand Down
2 changes: 2 additions & 0 deletions packages/apidash_design_system/lib/widgets/snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
SnackBar getSnackBar(
String text, {
bool small = true,
Color? color,
}) {
return SnackBar(
width: small ? 300 : 500,
backgroundColor: color,
behavior: SnackBarBehavior.floating,
content: Text(
text,
Expand Down