mirror of
https://github.com/foss42/apidash.git
synced 2025-06-13 17:09:07 +08:00
Resolved Issue #562
This commit is contained in:
0
OUTPUT/apidash-data.hive
Normal file
0
OUTPUT/apidash-data.hive
Normal file
0
OUTPUT/apidash-data.lock
Normal file
0
OUTPUT/apidash-data.lock
Normal file
0
OUTPUT/apidash-environments.hive
Normal file
0
OUTPUT/apidash-environments.hive
Normal file
0
OUTPUT/apidash-environments.lock
Normal file
0
OUTPUT/apidash-environments.lock
Normal file
0
OUTPUT/apidash-history-lazy.hive
Normal file
0
OUTPUT/apidash-history-lazy.hive
Normal file
0
OUTPUT/apidash-history-lazy.lock
Normal file
0
OUTPUT/apidash-history-lazy.lock
Normal file
0
OUTPUT/apidash-history-meta.hive
Normal file
0
OUTPUT/apidash-history-meta.hive
Normal file
0
OUTPUT/apidash-history-meta.lock
Normal file
0
OUTPUT/apidash-history-meta.lock
Normal file
@ -23,14 +23,61 @@ class HistorySidebarHeader extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
ADIconButton(
|
ADIconButton(
|
||||||
icon: Icons.delete_forever,
|
icon: Icons.delete_forever,
|
||||||
iconSize: kButtonIconSizeLarge,
|
iconSize: kButtonIconSizeLarge,
|
||||||
tooltip: "Clear History",
|
tooltip: "Clear History",
|
||||||
color: Theme.of(context).brightness == Brightness.dark
|
color: Theme.of(context).brightness == Brightness.dark
|
||||||
? kColorDarkDanger
|
? kColorDarkDanger
|
||||||
: kColorLightDanger,
|
: kColorLightDanger,
|
||||||
onPressed: () => hiveHandler.clearAllHistory(),
|
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(
|
ADIconButton(
|
||||||
icon: Icons.manage_history_rounded,
|
icon: Icons.manage_history_rounded,
|
||||||
iconSize: kButtonIconSizeLarge,
|
iconSize: kButtonIconSizeLarge,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import 'package:apidash/providers/history_providers.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
|
||||||
const String kDataBox = "apidash-data";
|
const String kDataBox = "apidash-data";
|
||||||
@ -140,10 +142,27 @@ class HiveHandler {
|
|||||||
|
|
||||||
Future<void> deleteHistoryRequest(String id) => historyLazyBox.delete(id);
|
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 historyMetaBox.clear();
|
||||||
await historyLazyBox.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 {
|
Future clear() async {
|
||||||
await dataBox.clear();
|
await dataBox.clear();
|
||||||
|
@ -59,4 +59,4 @@ class HttpClientManager {
|
|||||||
bool hasActiveClient(String requestId) {
|
bool hasActiveClient(String requestId) {
|
||||||
return _clients.containsKey(requestId);
|
return _clients.containsKey(requestId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -133,4 +133,4 @@ Future<(HttpResponse?, Duration?, String?)> request(
|
|||||||
} else {
|
} else {
|
||||||
return (null, null, uriRec.$2);
|
return (null, null, uriRec.$2);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user