From b88f484bc3fce49bd53b88afd85360d9d680b2e7 Mon Sep 17 00:00:00 2001 From: Amoghhosamane Date: Thu, 5 Mar 2026 22:49:56 +0530 Subject: [PATCH] feat: add delete all button to history #65 --- analyze_out_new.txt | Bin 0 -> 200 bytes lib/constants/colours.dart | 3 + lib/widgets/history.dart | 81 +++++++++++++++++- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 analyze_out_new.txt diff --git a/analyze_out_new.txt b/analyze_out_new.txt new file mode 100644 index 0000000000000000000000000000000000000000..41c1fd340609197ef70a021bd573a0e17b11fe14 GIT binary patch literal 200 zcmezW&ygXIA(0`6p^~ABArr_>XHWpsc?_uxMGOTD`3xxxdSIvkl%YQ4W#D4)1KI+z vwHOFXf%X;yd1*kgQlNWM7!-j#4WL^Rfjo%Y6c`K{%z { ElevatedButton( onPressed: () => Navigator.pop(context, true), style: ElevatedButton.styleFrom( - backgroundColor: Colors.redAccent.withValues(alpha: 0.1), - foregroundColor: Colors.redAccent, + backgroundColor: colours.error.withValues(alpha: 0.1), + foregroundColor: colours.error, elevation: 0, ), child: const Text('Delete'), @@ -182,6 +183,70 @@ class _HistoryState extends State { } } + Future _deleteAllSessions() async { + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Delete All Sessions'), + content: const Text( + 'Are you sure you want to delete ALL sessions? This action cannot be undone.', + style: TextStyle(fontSize: 16), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + ElevatedButton( + onPressed: () => Navigator.pop(context, true), + style: ElevatedButton.styleFrom( + backgroundColor: colours.error.withValues(alpha: 0.1), + foregroundColor: colours.error, + elevation: 0, + ), + child: const Text('Delete All'), + ), + ], + ), + ); + + if (confirmed == true) { + await _performDeleteAll(); + } + } + + Future _performDeleteAll() async { + setState(() => _isLoading = true); + try { + final newContent = serializeSessions([]); + await writePod( + 'sessions.ttl', + newContent, + overwrite: true, + ); + await _loadSessions(); + } on SecurityKeyNotAvailableException { + debugPrint( + 'Security key missing - cannot write sessions.ttl for bulk deletion', + ); + if (mounted) { + await getKeyFromUserIfRequired(context, widget); + if (mounted) { + await _performDeleteAll(); + } + } + } catch (e) { + debugPrint('Error deleting all sessions: $e'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to delete all sessions: $e')), + ); + } + } finally { + if (mounted) setState(() => _isLoading = false); + } + } + Future _editSession(Map session) async { final titleController = TextEditingController(text: session['title']); final descriptionController = @@ -280,8 +345,18 @@ class _HistoryState extends State { title: const Text('Session History'), automaticallyImplyLeading: false, // Don't show back button actions: [ + if (_sessions.isNotEmpty) + IconButton( + icon: const Icon( + Icons.delete_sweep_outlined, + color: colours.error, + ), + tooltip: 'Delete all sessions', + onPressed: _deleteAllSessions, + ), IconButton( icon: const Icon(Icons.refresh), + tooltip: 'Refresh', onPressed: _loadSessions, ), const SizedBox(width: 8), @@ -411,7 +486,7 @@ class _HistoryState extends State { icon: const Icon( Icons.delete_outline, size: 20, - color: Colors.redAccent, + color: colours.error, ), onPressed: () => _deleteSession(session['rawStart']!), diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index e8e5160..041bd40 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { @@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("FastRsaPlugin")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); + PrintingPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PrintingPlugin")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index edc357f..ff1f580 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST audioplayers_windows fast_rsa flutter_secure_storage_windows + printing url_launcher_windows )