SharedState<T> constructor
SharedState<T> ()
Creates a new SharedState instance.
The state type identifier is automatically derived from the generic
type T using T.toString().
Upon creation:
- Registers a listener with SharedStateManager
- Loads cached state if available
- Syncs state from native side asynchronously
Implementation
SharedState() : _type = T.toString() {
// Automatically register listener with SharedStateManager
SharedStateManager.instance.addStateChangeListener(_type, _onStateChange);
// Initialize with cached state if available
final cachedState = SharedStateManager.instance.getCachedState(_type);
if (cachedState != null) {
_state = fromJson(cachedState);
debugPrint('[SharedState] Initial cached state for $_type: $_state');
} else {
// Sync state asynchronously
_syncState();
}
}