backdoorStaticGlobal<St> static method
Store<St>
backdoorStaticGlobal<St>()
Avoid using if you don't have a good reason to do so.
The backdoorStaticGlobal gives you direct access to the store for advanced use-cases.
It does NOT need the context, as it gets the store from the static
field _staticStoreBackdoor
. Note this field is set when the StoreProvider is created,
which assumes the StoreProvider is used only once in your app. This is usually a
reasonable assumption, but can break in tests. It does NOT create a dependency
like _getStoreWithDependency_Untyped
does, and it does NOT rebuild the state when the state changes,
when you access it like this: var state = StoreProvider.backdoorStaticGlobal<AppState>().state;
.
Implementation
static Store<St> backdoorStaticGlobal<St>() {
if (_staticStoreBackdoor == null)
throw StoreException('Error: No Redux store found. '
'Did you forget to use the StoreProvider?');
if (_staticStoreBackdoor is! Store<St>) {
var type = _typeOf<Store<St>>;
throw StoreException('Error: Store is of type ${_staticStoreBackdoor.runtimeType} '
'and not of type $type. Please provide the correct type.');
}
return _staticStoreBackdoor as Store<St>;
}