BlocScope<T extends IStateObservable<Object?> >.create constructor
BlocScope<T extends IStateObservable<Object?> >.create ({})
Takes a Create function that is responsible for
creating the Bloc and a child which will have access
to the instance via BlocScope.of(context)
.
It is used as a dependency injection (DI) widget so that a single instance
of a Bloc can be provided to multiple widgets within a subtree.
BlocScope(
create: (BuildContext context) => BlocA(),
child: ChildA(),
);
It automatically handles closing the instance when used with Create. By default, Create is called only when the instance is accessed.
BlocScope(
create: (BuildContext context) => BlocA(),
child: ChildA(),
);
Implementation
BlocScope.create({
required Create<T> create,
this.child,
Key? key,
}) : _create = create,
_value = null,
super(key: key);