diff --git a/OUTPUT/apidash-data.hive b/OUTPUT/apidash-data.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-data.lock b/OUTPUT/apidash-data.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-environments.hive b/OUTPUT/apidash-environments.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-environments.lock b/OUTPUT/apidash-environments.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-lazy.hive b/OUTPUT/apidash-history-lazy.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-lazy.lock b/OUTPUT/apidash-history-lazy.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-meta.hive b/OUTPUT/apidash-history-meta.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-meta.lock b/OUTPUT/apidash-history-meta.lock new file mode 100644 index 00000000..e69de29b diff --git a/lib/screens/history/history_widgets/his_sidebar_header.dart b/lib/screens/history/history_widgets/his_sidebar_header.dart index ad6fb1da..2fd07fef 100644 --- a/lib/screens/history/history_widgets/his_sidebar_header.dart +++ b/lib/screens/history/history_widgets/his_sidebar_header.dart @@ -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, diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index 5ca47607..6388b008 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -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 deleteHistoryRequest(String id) => historyLazyBox.delete(id); - Future clearAllHistory() async { +Future 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(); diff --git a/packages/apidash_core/lib/services/http_client_manager.dart b/packages/apidash_core/lib/services/http_client_manager.dart index bec23214..d4fd4ca5 100644 --- a/packages/apidash_core/lib/services/http_client_manager.dart +++ b/packages/apidash_core/lib/services/http_client_manager.dart @@ -59,4 +59,4 @@ class HttpClientManager { bool hasActiveClient(String requestId) { return _clients.containsKey(requestId); } -} +} \ No newline at end of file diff --git a/packages/apidash_core/lib/services/http_service.dart b/packages/apidash_core/lib/services/http_service.dart index 0bbc0501..cad9018b 100644 --- a/packages/apidash_core/lib/services/http_service.dart +++ b/packages/apidash_core/lib/services/http_service.dart @@ -133,4 +133,4 @@ Future<(HttpResponse?, Duration?, String?)> request( } else { return (null, null, uriRec.$2); } -} +} \ No newline at end of file