| name | use-props |
| description | Use Superpowers.setProp() and prop() for key-value storage with automatic cleanup on logout or test reset |
Use Props for Shared Data with Auto-Cleanup
This skill uses Superpowers.setProp() and Superpowers.prop() for key-value storage with automatic cleanup.
What This Skill Does
Uses the props system to:
- Store shared data (timers, subscriptions, services)
- Retrieve data from anywhere in the app
- Automatically dispose resources on logout/test reset
Instructions
Step 1: Store Data with setProp()
import 'package:bloc_superpowers/bloc_superpowers.dart';
// Store a timer
Superpowers.setProp('refreshTimer', Timer.periodic(
Duration(minutes: 5),
(_) => refreshData(),
));
// Store a stream subscription
Superpowers.setProp('authSubscription', authStream.listen((user) {
handleAuthChange(user);
}));
// Store any value
Superpowers.setProp('lastSyncTime', DateTime.now());
Step 2: Retrieve Data with prop()
// Get the timer
final timer = Superpowers.prop<Timer>('refreshTimer');
timer?.cancel();
// Get the subscription
final sub = Superpowers.prop<StreamSubscription>('authSubscription');
// Get any value
final lastSync = Superpowers.prop<DateTime>('lastSyncTime');
Step 3: Automatic Cleanup
Props are automatically disposed when calling clear() or prepareToLogout():
// In tests - resets everything
setUp(() {
Superpowers.clear();
});
// On logout - clears user data, keeps app config
Future<void> logout() async {
await Superpowers.prepareToLogout();
await authService.signOut();
}
Key Types
Keys can be strings, enums, types, or records:
// String keys
Superpowers.setProp('refreshTimer', timer);
Superpowers.prop<Timer>('refreshTimer');
// Enum keys
enum PropKey { authToken, refreshTimer, syncSubscription }
Superpowers.setProp(PropKey.authToken, 'abc123');
Superpowers.prop<String>(PropKey.authToken);
// Type keys
Superpowers.setProp(MyService, MyService());
Superpowers.prop<MyService>(MyService);
// Record keys (for multiple instances)
Superpowers.setProp((Database, 'primary'), primaryDb);
Superpowers.setProp((Database, 'cache'), cacheDb);
Superpowers.prop<Database>((Database, 'primary'));