flutter_storage_inspector 0.2.0
flutter_storage_inspector: ^0.2.0 copied to clipboard
A debug-only Flutter package for inspecting, searching, editing, exporting, and managing local application storage with a developer-focused UI.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_storage_inspector/flutter_storage_inspector.dart';
import 'package:get_storage/get_storage.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
const String _getStorageContainer = 'inspector_demo';
const String _hiveBoxName = 'inspector_demo_box';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
await Hive.openBox<dynamic>(_hiveBoxName);
await GetStorage.init(_getStorageContainer);
await _seedInitialData();
final adapters = StorageInspectorAdapters.defaults(
getStorageContainers: const <String>[_getStorageContainer],
hiveBoxes: const <String>[_hiveBoxName],
);
final controller = StorageInspectorController(adapters: adapters);
runApp(
StorageInspector(
enabled: kDebugMode,
adapters: adapters,
controller: controller,
options: const StorageInspectorOptions(
title: 'Local Storage Inspector',
showBubble: true,
enableLongPressGesture: true,
tapCountToOpen: 3,
),
child: ExampleApp(controller: controller),
),
);
}
Future<void> _seedInitialData() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('profile_name', 'Taylor Rivera');
await prefs.setBool('feature_flag_beta', true);
await prefs.setStringList('favorite_tags', <String>['debug', 'flutter']);
final asyncPrefs = SharedPreferencesAsync();
await asyncPrefs.setString(
'async_profile',
'{"role":"developer","experience":"senior"}',
);
await asyncPrefs.setInt('build_count', 14);
final getStorage = GetStorage(_getStorageContainer);
await getStorage.write('session', <String, Object?>{
'active': true,
'id': 'session-001',
'scopes': <String>['read', 'write'],
});
await getStorage.write('last_sync_ms', DateTime.now().millisecondsSinceEpoch);
final secureStorage = const FlutterSecureStorage();
await secureStorage.write(
key: 'token_preview',
value: 'abc123-preview-token',
);
await secureStorage.write(
key: 'secure_payload',
value: '{"scopes":["profile","payments"],"expiresIn":3600}',
);
final hiveBox = Hive.box<dynamic>(_hiveBoxName);
await hiveBox.put('user_settings', <String, Object?>{
'theme': 'system',
'notifications': true,
'pageSize': 25,
});
await hiveBox.put('recent_projects', <String>['atlas', 'mercury', 'nova']);
}
class ExampleApp extends StatelessWidget {
const ExampleApp({required this.controller, super.key});
final StorageInspectorController controller;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Storage Inspector Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF0F766E)),
),
home: ExampleHomePage(controller: controller),
);
}
}
class ExampleHomePage extends StatefulWidget {
const ExampleHomePage({required this.controller, super.key});
final StorageInspectorController controller;
@override
State<ExampleHomePage> createState() => _ExampleHomePageState();
}
class _ExampleHomePageState extends State<ExampleHomePage> {
final FlutterSecureStorage _secureStorage = const FlutterSecureStorage();
String _status = 'Sample data seeded. Open the inspector from the bubble.';
int _counter = 0;
Future<void> _refreshStatus(String message) async {
await widget.controller.refreshAll();
if (!mounted) {
return;
}
setState(() {
_status = message;
});
}
Future<void> _mutateData() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('tap_counter', _counter + 1);
final asyncPrefs = SharedPreferencesAsync();
await asyncPrefs.setDouble('cache_hit_rate', 92.4 + _counter);
final getStorage = GetStorage(_getStorageContainer);
await getStorage.write('session', <String, Object?>{
'active': true,
'id': 'session-${_counter + 2}',
'scopes': <String>['read', 'write', 'inspect'],
});
await _secureStorage.write(
key: 'token_preview',
value: 'token-${DateTime.now().millisecondsSinceEpoch}',
);
final hiveBox = Hive.box<dynamic>(_hiveBoxName);
await hiveBox.put('build_notes', <String, Object?>{
'counter': _counter + 1,
'timestamp': DateTime.now().toIso8601String(),
});
setState(() {
_counter += 1;
});
await _refreshStatus(
'Sample data mutated. Refresh is automatic and manual.',
);
}
Future<void> _clearDemoData() async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
final asyncPrefs = SharedPreferencesAsync();
await asyncPrefs.clear();
final getStorage = GetStorage(_getStorageContainer);
await getStorage.erase();
await _secureStorage.deleteAll();
final hiveBox = Hive.box<dynamic>(_hiveBoxName);
await hiveBox.clear();
await _refreshStatus('All demo data cleared.');
}
Future<void> _reseedingData() async {
await _seedInitialData();
await _refreshStatus('Demo data seeded again.');
}
Future<void> _openFullscreenInspector() async {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) {
return StorageInspectorScreen(
controller: widget.controller,
title: 'Local Storage Inspector',
);
},
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('Storage Inspector Demo')),
body: ListView(
padding: const EdgeInsets.all(20),
children: [
DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
theme.colorScheme.primaryContainer,
theme.colorScheme.tertiaryContainer,
],
),
borderRadius: BorderRadius.circular(28),
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Debug local storage like a first-class tool.',
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w800,
),
),
const SizedBox(height: 12),
Text(_status, style: theme.textTheme.bodyLarge),
const SizedBox(height: 20),
Wrap(
spacing: 12,
runSpacing: 12,
children: [
FilledButton.icon(
onPressed: _openFullscreenInspector,
icon: const Icon(Icons.open_in_full_rounded),
label: const Text('Open Full Screen Inspector'),
),
OutlinedButton.icon(
onPressed: _mutateData,
icon: const Icon(Icons.edit_note_rounded),
label: const Text('Mutate Demo Data'),
),
OutlinedButton.icon(
onPressed: _reseedingData,
icon: const Icon(Icons.data_array_rounded),
label: const Text('Seed Demo Data'),
),
OutlinedButton.icon(
onPressed: _clearDemoData,
icon: const Icon(Icons.delete_outline_rounded),
label: const Text('Clear Demo Data'),
),
],
),
],
),
),
),
const SizedBox(height: 20),
Wrap(
spacing: 16,
runSpacing: 16,
children: const [
_InfoCard(
title: 'Overlay',
body: 'Use the floating bubble to open the inspector anywhere.',
),
_InfoCard(
title: 'Keyboard Shortcut',
body: 'Press Ctrl + Shift + D on desktop platforms.',
),
_InfoCard(
title: 'Gesture',
body:
'Triple tap or long press anywhere in the app to open it.',
),
],
),
const SizedBox(height: 20),
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Supported backends in this example',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 12),
const Text(
'SharedPreferences, SharedPreferences Async, GetStorage, '
'Flutter Secure Storage, and Hive are all seeded with sample '
'data so the inspector opens with realistic content.',
),
],
),
),
),
],
),
);
}
}
class _InfoCard extends StatelessWidget {
const _InfoCard({required this.title, required this.body});
final String title;
final String body;
@override
Widget build(BuildContext context) {
return SizedBox(
width: 280,
child: Card(
child: Padding(
padding: const EdgeInsets.all(18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(
context,
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700),
),
const SizedBox(height: 10),
Text(body),
],
),
),
),
);
}
}