buildActions method
Optional actions to show in the console toolbar
Implementation
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
tooltip: 'Export All Entries',
icon: const Icon(Icons.share),
onPressed: () {
final entries = StorageInspectorStore.entries;
if (entries.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No storage entries to export')),
);
return;
}
final text = const JsonEncoder.withIndent(
' ',
).convert({for (final e in entries) e.key: e.value});
ExportUtil.exportData(text: text, title: 'SharedPreferences');
},
),
IconButton(
tooltip: 'Clear All Entries',
icon: const Icon(Icons.delete),
onPressed: () async {
final confirmed = await showDialog<bool>(
context: context,
builder:
(ctx) => AlertDialog(
title: const Text('Clear All Entries?'),
content: const Text(
'This will permanently delete every SharedPreferences entry.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text('Clear'),
),
],
),
);
if (confirmed ?? false) await StorageInspectorStore.clearAll();
},
),
];
}