mirror of
https://github.com/foss42/apidash.git
synced 2025-06-29 04:16:12 +08:00
Merge pull request #569 from nope3472/resolve-issue-history-clear
Resolved Issue #562
This commit is contained in:
@ -473,3 +473,9 @@ const kMsgNoContent = "No content";
|
|||||||
const kMsgUnknowContentType = "Unknown Response Content-Type";
|
const kMsgUnknowContentType = "Unknown Response Content-Type";
|
||||||
// Workspace Selector
|
// Workspace Selector
|
||||||
const kMsgSelectWorkspace = "Create your workspace";
|
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';
|
||||||
|
@ -11,6 +11,7 @@ class HistorySidebarHeader extends ConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final mobileScaffoldKey = ref.read(mobileScaffoldKeyStateProvider);
|
final mobileScaffoldKey = ref.read(mobileScaffoldKeyStateProvider);
|
||||||
|
final sm = ScaffoldMessenger.of(context);
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: kPe4,
|
padding: kPe4,
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -28,10 +29,29 @@ class HistorySidebarHeader extends ConsumerWidget {
|
|||||||
color: Theme.of(context).brightness == Brightness.dark
|
color: Theme.of(context).brightness == Brightness.dark
|
||||||
? kColorDarkDanger
|
? kColorDarkDanger
|
||||||
: kColorLightDanger,
|
: kColorLightDanger,
|
||||||
onPressed: () async {
|
onPressed: () {
|
||||||
await ref
|
showOkCancelDialog(
|
||||||
.read(historyMetaStateNotifier.notifier)
|
context,
|
||||||
.clearAllHistory();
|
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(
|
ADIconButton(
|
||||||
|
47
lib/widgets/dialog_ok_cancel.dart
Normal file
47
lib/widgets/dialog_ok_cancel.dart
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -16,6 +16,7 @@ export 'codegen_previewer.dart';
|
|||||||
export 'dialog_about.dart';
|
export 'dialog_about.dart';
|
||||||
export 'dialog_history_retention.dart';
|
export 'dialog_history_retention.dart';
|
||||||
export 'dialog_import.dart';
|
export 'dialog_import.dart';
|
||||||
|
export 'dialog_ok_cancel.dart';
|
||||||
export 'dialog_rename.dart';
|
export 'dialog_rename.dart';
|
||||||
export 'dialog_text.dart';
|
export 'dialog_text.dart';
|
||||||
export 'drag_and_drop_area.dart';
|
export 'drag_and_drop_area.dart';
|
||||||
|
@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
|
|||||||
SnackBar getSnackBar(
|
SnackBar getSnackBar(
|
||||||
String text, {
|
String text, {
|
||||||
bool small = true,
|
bool small = true,
|
||||||
|
Color? color,
|
||||||
}) {
|
}) {
|
||||||
return SnackBar(
|
return SnackBar(
|
||||||
width: small ? 300 : 500,
|
width: small ? 300 : 500,
|
||||||
|
backgroundColor: color,
|
||||||
behavior: SnackBarBehavior.floating,
|
behavior: SnackBarBehavior.floating,
|
||||||
content: Text(
|
content: Text(
|
||||||
text,
|
text,
|
||||||
|
Reference in New Issue
Block a user