getStorageItem function
Get a storage item (replaces cookie functionality)
name - Storage key name
Returns stored value or null if not found/expired
Implementation
Future<String?> getStorageItem(String name) async {
try {
final prefs = await SharedPreferences.getInstance();
final data = prefs.getString(name);
if (data == null) return null;
final parsed = jsonDecode(data) as Map<String, dynamic>;
// Check if expired
if (parsed['expires'] != null &&
DateTime.now().millisecondsSinceEpoch > parsed['expires']) {
await prefs.remove(name);
return null;
}
return parsed['value'] as String?;
} catch (e) {
return null;
}
}