getBloc<B extends IsolateBlocBase<Object, S> , S> function
Use this function to communicate with IsolateBlocBase in Isolate
.
To get bloc in UI Isolate use IsolateBlocProvider which returns IsolateBlocWrapper.
This function works this way:
- waits for user's Initializer function
- looks for created bloc with BlocA type
- if it finds any, so returns this bloc's IsolateBlocWrapper
- else it creates a new bloc and adds to the pull of free blocs.
So when UI will call
create()
, it won't create a new bloc but return free bloc from pull.
Throws IsolateManagerUnInitialized if IsolateManager is null.
An example of how to provide Weather bloc to Theme bloc:
void isolatedFunc() {
register<ThemeBloc, ThemeState>(
create: () => ThemeBloc(
weatherBloc: getBloc<WeatherBloc, WeatherState>(),
),
);
}
Implementation
IsolateBlocWrapper<S> getBloc<B extends IsolateBlocBase<Object, S>, S>() {
final isolateManager = IsolateManager.instance;
if (isolateManager == null) {
throw IsolateManagerUnInitialized();
} else {
return isolateManager.getBlocWrapper<B, S>();
}
}