Skip to content

Commit 1deacc6

Browse files
committed
Resolved Issue #562
1 parent d67ea65 commit 1deacc6

12 files changed

+76
-10
lines changed

OUTPUT/apidash-data.hive

Whitespace-only changes.

OUTPUT/apidash-data.lock

Whitespace-only changes.

OUTPUT/apidash-environments.hive

Whitespace-only changes.

OUTPUT/apidash-environments.lock

Whitespace-only changes.

OUTPUT/apidash-history-lazy.hive

Whitespace-only changes.

OUTPUT/apidash-history-lazy.lock

Whitespace-only changes.

OUTPUT/apidash-history-meta.hive

Whitespace-only changes.

OUTPUT/apidash-history-meta.lock

Whitespace-only changes.

lib/screens/history/history_widgets/his_sidebar_header.dart

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,61 @@ class HistorySidebarHeader extends ConsumerWidget {
2323
),
2424
const Spacer(),
2525
ADIconButton(
26-
icon: Icons.delete_forever,
27-
iconSize: kButtonIconSizeLarge,
28-
tooltip: "Clear History",
29-
color: Theme.of(context).brightness == Brightness.dark
30-
? kColorDarkDanger
31-
: kColorLightDanger,
32-
onPressed: () => hiveHandler.clearAllHistory(),
26+
icon: Icons.delete_forever,
27+
iconSize: kButtonIconSizeLarge,
28+
tooltip: "Clear History",
29+
color: Theme.of(context).brightness == Brightness.dark
30+
? kColorDarkDanger
31+
: kColorLightDanger,
32+
onPressed: () {
33+
showDialog(
34+
context: context,
35+
builder: (context) => AlertDialog(
36+
title: const Text('Clear History'),
37+
content: const Text('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 hiveHandler.clearAllHistory(ref); // ✅ Pass `ref` here
47+
48+
if (context.mounted) {
49+
Navigator.pop(context);
50+
ScaffoldMessenger.of(context).showSnackBar(
51+
const SnackBar(
52+
content: Text('History cleared successfully'),
53+
duration: Duration(seconds: 2),
54+
),
55+
);
56+
}
57+
} catch (e) {
58+
if (context.mounted) {
59+
Navigator.pop(context);
60+
ScaffoldMessenger.of(context).showSnackBar(
61+
const SnackBar(
62+
content: Text('Error clearing history'),
63+
backgroundColor: Colors.red,
64+
duration: Duration(seconds: 2),
65+
),
66+
);
67+
}
68+
}
69+
},
70+
style: TextButton.styleFrom(
71+
foregroundColor: Theme.of(context).colorScheme.error,
72+
),
73+
child: const Text('Clear'),
3374
),
75+
],
76+
),
77+
);
78+
},
79+
),
80+
3481
ADIconButton(
3582
icon: Icons.manage_history_rounded,
3683
iconSize: kButtonIconSizeLarge,

lib/services/hive_services.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:apidash/providers/history_providers.dart';
12
import 'package:flutter/foundation.dart';
3+
import 'package:flutter_riverpod/flutter_riverpod.dart';
24
import 'package:hive_flutter/hive_flutter.dart';
35

46
const String kDataBox = "apidash-data";
@@ -140,10 +142,27 @@ class HiveHandler {
140142

141143
Future<void> deleteHistoryRequest(String id) => historyLazyBox.delete(id);
142144

143-
Future clearAllHistory() async {
145+
Future<void> clearAllHistory(WidgetRef ref) async {
146+
try {
147+
await historyMetaBox.put(kHistoryBoxIds, null);
144148
await historyMetaBox.clear();
145149
await historyLazyBox.clear();
150+
151+
// ✅ Now ref is passed correctly
152+
ref.read(selectedHistoryIdStateProvider.notifier).state = null;
153+
ref.read(selectedRequestGroupIdStateProvider.notifier).state = null;
154+
ref.read(selectedHistoryRequestModelProvider.notifier).state = null;
155+
ref.read(historySequenceProvider.notifier).state = null;
156+
ref.read(historyMetaStateNotifier.notifier).state = null;
157+
158+
} catch (e) {
159+
debugPrint("ERROR CLEARING HISTORY: $e");
160+
rethrow;
146161
}
162+
}
163+
164+
165+
147166

148167
Future clear() async {
149168
await dataBox.clear();

0 commit comments

Comments
 (0)