Local storage with GetStorage for preferences, caching, and offline-first patterns
Implements GetStorage patterns for local data persistence, caching, and offline-first Flutter apps.
/plugin marketplace add Kaakati/rails-enterprise-dev/plugin install reactree-flutter-dev@manifest-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
// main.dart
void main() async {
await GetStorage.init();
runApp(MyApp());
}
class StorageService {
final GetStorage _box;
StorageService() : _box = GetStorage();
// Token management
String? get token => _box.read<String>('auth_token');
Future<void> setToken(String token) => _box.write('auth_token', token);
Future<void> clearToken() => _box.remove('auth_token');
// User data
Map<String, dynamic>? get userData => _box.read<Map<String, dynamic>>('user_data');
Future<void> setUserData(Map<String, dynamic> data) => _box.write('user_data', data);
// Preferences
bool get isDarkMode => _box.read<bool>('dark_mode') ?? false;
Future<void> setDarkMode(bool value) => _box.write('dark_mode', value);
String get locale => _box.read<String>('locale') ?? 'en';
Future<void> setLocale(String locale) => _box.write('locale', locale);
// Clear all
Future<void> clearAll() => _box.erase();
// Listen to changes
void listenKey(String key, Function(dynamic) callback) {
_box.listenKey(key, callback);
}
}
class UserLocalDataSource {
final GetStorage _storage;
static const String _usersKey = 'cached_users';
static const String _userKeyPrefix = 'cached_user_';
static const Duration _cacheDuration = Duration(hours: 24);
UserLocalDataSource(this._storage);
Future<void> cacheUser(UserModel user) async {
final cacheData = {
'user': user.toJson(),
'timestamp': DateTime.now().toIso8601String(),
};
await _storage.write('$_userKeyPrefix${user.id}', cacheData);
}
Future<UserModel?> getCachedUser(String id) async {
final cacheData = _storage.read<Map<String, dynamic>>('$_userKeyPrefix$id');
if (cacheData == null) return null;
// Check cache expiration
final timestamp = DateTime.parse(cacheData['timestamp']);
if (DateTime.now().difference(timestamp) > _cacheDuration) {
await _storage.remove('$_userKeyPrefix$id');
return null;
}
return UserModel.fromJson(cacheData['user']);
}
Future<void> cacheUsers(List<UserModel> users) async {
final cacheData = {
'users': users.map((u) => u.toJson()).toList(),
'timestamp': DateTime.now().toIso8601String(),
};
await _storage.write(_usersKey, cacheData);
}
Future<List<UserModel>?> getCachedUsers() async {
final cacheData = _storage.read<Map<String, dynamic>>(_usersKey);
if (cacheData == null) return null;
final timestamp = DateTime.parse(cacheData['timestamp']);
if (DateTime.now().difference(timestamp) > _cacheDuration) {
await _storage.remove(_usersKey);
return null;
}
final List<dynamic> usersList = cacheData['users'];
return usersList.map((json) => UserModel.fromJson(json)).toList();
}
Future<void> clearCache() async {
await _storage.erase();
}
}
class CacheService extends GetxService {
final GetStorage _storage;
CacheService() : _storage = GetStorage();
Future<CacheService> init() async {
await GetStorage.init();
return this;
}
// Reactive cache
final _cachedData = <String, dynamic>{}.obs;
T? get<T>(String key) {
return _storage.read<T>(key);
}
Future<void> put<T>(String key, T value, {Duration? expiry}) async {
if (expiry != null) {
final expiryData = {
'value': value,
'expiry': DateTime.now().add(expiry).toIso8601String(),
};
await _storage.write(key, expiryData);
} else {
await _storage.write(key, value);
}
_cachedData[key] = value;
}
Future<void> remove(String key) async {
await _storage.remove(key);
_cachedData.remove(key);
}
bool has(String key) {
return _storage.hasData(key);
}
}
read<String>, read<int>, etc.)This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.