BlocProvider<T extends Bloc> class
Provides BLoC via this Provider.
BLoC's lifecycle is associated with the state that the provider has internally.
This can be called directory(see constructor documentation), or you can define a class as below.
Example
class CounterBlocProvider extends BlocProvider<CounterBloc> {
CounterBlocProvider({
@required Widget child,
}) : super(
child: child,
creator: (context, _bag) {
assert(context != null);
return CounterBloc();
},
);
static CounterBloc of(BuildContext context) => BlocProvider.of(context);
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BlocProvider
Constructors
-
BlocProvider({Key? key, required BlocCreator<
T> creator, Widget? child, bool autoDispose = true}) - Constructor for simple usage.
-
BlocProvider.builder({Key? key, required BlocCreator<
T> creator, required BlocBuilder<T> builder, bool autoDispose = true}) -
Constructor for advanced usage.
const
- BlocProvider.fromBloc({Key? key, required T bloc, required Widget child})
- Pass the bloc which is managed by other widget.
- BlocProvider.fromBlocContext({Key? key, required BuildContext context, required Widget child})
- Pass the context that contains bloc which is managed by other widget.
Properties
- autoDispose → bool
-
final
-
builder
→ BlocBuilder<
T> -
final
-
creator
→ BlocCreator<
T> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
Widget child) → BlocProvider< T> - Clone the current BlocProvider with a new child Widget.
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _BlocProviderState< Bloc> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
maybeOf<
BlocType extends Bloc> (BuildContext context) → BlocType? -
of<
BlocType extends Bloc> (BuildContext context) → BlocType -
Return the
BlocType
of the closest ancestor_Inherited
.