register<T extends IsolateBlocBase<Object?, S>, S> function

void register<T extends IsolateBlocBase<Object?, S>, S>({
  1. required IsolateBlocCreator<Object?, S> create,
  2. S? initialState,
})

Registers IsolateBlocBase. This allows you to create it in UI Isolate using createBloc function.

This function may be called only in Initializer (function which is called in Isolate).

If initialState is not provided bloc will be created immediately. So if you don't want to create bloc while initialization please provide initialState!

Throws IsolateManagerUnInitialized if IsolateManager is null. It may happen only if you call this function from UI Isolate.

How to use:

void isolatedFunc() {
  register<CounterCubit, int>(create: () => CounterCubit());
}

Implementation

void register<T extends IsolateBlocBase<Object?, S>, S>({
  required IsolateBlocCreator<Object?, S> create,
  S? initialState,
}) {
  final isolateManager = IsolateManager.instance;
  if (isolateManager == null) {
    throw IsolateManagerUnInitialized();
  } else {
    isolateManager.registerBloc<T, S>(create, initialState: initialState);
  }
}