BlocProvider<T extends Bloc>.fromBloc constructor

BlocProvider<T extends Bloc>.fromBloc({
  1. Key? key,
  2. required T bloc,
  3. required Widget child,
})

Pass the bloc which is managed by other widget.

Passed bloc won't be disposed automatically, so it should be managed appropriately.

Typical use case is this:

  1. The bloc is managed by BlocProvider or BlocProvider.builder
  2. Pass the bloc to other widgets tree without dispose management

See also BlocProvider.fromBlocContext

Example

BlocProvider<CounterBloc>.fromBloc(
  bloc: BlocProvider<CounterBloc>.of(context),
  child: AnotherPage(),
)

Implementation

BlocProvider.fromBloc({
  Key? key,
  required T bloc,
  required Widget child,
}) : this(
        key: key,
        creator: (_context, _bag) => bloc,
        child: child,
        autoDispose: false,
      );