mirror of
https://github.com/foss42/apidash.git
synced 2025-06-04 01:13:30 +08:00
Resolved Issue #562
This commit is contained in:
@ -23,14 +23,61 @@ class HistorySidebarHeader extends ConsumerWidget {
|
||||
),
|
||||
const Spacer(),
|
||||
ADIconButton(
|
||||
icon: Icons.delete_forever,
|
||||
iconSize: kButtonIconSizeLarge,
|
||||
tooltip: "Clear History",
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? kColorDarkDanger
|
||||
: kColorLightDanger,
|
||||
onPressed: () => hiveHandler.clearAllHistory(),
|
||||
icon: Icons.delete_forever,
|
||||
iconSize: kButtonIconSizeLarge,
|
||||
tooltip: "Clear History",
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? kColorDarkDanger
|
||||
: kColorLightDanger,
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Clear History'),
|
||||
content: const Text('Are you sure you want to clear all history? This action cannot be undone.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
await hiveHandler.clearAllHistory(ref); // ✅ Pass `ref` here
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('History cleared successfully'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Error clearing history'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
child: const Text('Clear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
ADIconButton(
|
||||
icon: Icons.manage_history_rounded,
|
||||
iconSize: kButtonIconSizeLarge,
|
||||
|
@ -1,4 +1,6 @@
|
||||
import 'package:apidash/providers/history_providers.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
const String kDataBox = "apidash-data";
|
||||
@ -140,10 +142,27 @@ class HiveHandler {
|
||||
|
||||
Future<void> deleteHistoryRequest(String id) => historyLazyBox.delete(id);
|
||||
|
||||
Future clearAllHistory() async {
|
||||
Future<void> clearAllHistory(WidgetRef ref) async {
|
||||
try {
|
||||
await historyMetaBox.put(kHistoryBoxIds, null);
|
||||
await historyMetaBox.clear();
|
||||
await historyLazyBox.clear();
|
||||
|
||||
// ✅ Now ref is passed correctly
|
||||
ref.read(selectedHistoryIdStateProvider.notifier).state = null;
|
||||
ref.read(selectedRequestGroupIdStateProvider.notifier).state = null;
|
||||
ref.read(selectedHistoryRequestModelProvider.notifier).state = null;
|
||||
ref.read(historySequenceProvider.notifier).state = null;
|
||||
ref.read(historyMetaStateNotifier.notifier).state = null;
|
||||
|
||||
} catch (e) {
|
||||
debugPrint("ERROR CLEARING HISTORY: $e");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Future clear() async {
|
||||
await dataBox.clear();
|
||||
|
Reference in New Issue
Block a user