BlocProvider<B extends Bloc> class
Widget that responsible to create the Bloc with help of create function. Accepts any Widget as child and provides the ability for child to obtain the Bloc.
Function shouldNotify define whether that widgets that inherit from this widget should be rebuilt if Bloc was changed.
BlocProvider could subscribe on Bloc.navigationStream and receives navigation events if router function will be defined, similar as RouteListener.
class CounterScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider<CounterBloc>(
routerPrecondition: (prevSettings, settings) => (settings.arguments as int) % 5 == 0,
create: () => CounterBloc(),
child: CounterLayout(title: 'Bloc Demo Home Page'),
router: (context, name, args) {
return showDialog(
context: context,
builder: (_) {
return WillPopScope(
child: AlertDialog(
title: Text('Congratulations! You clicked $args times'),
),
onWillPop: () async {
Navigator.of(context).pop('Dialog with $args clicks has been closed');
return false;
}
);
}
);
},
);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BlocProvider
Constructors
-
BlocProvider({Key? key, required Widget child, required B create(), BlocRouter? router, UpdateShouldNotify<
B> ? shouldNotify, Precondition<RouteData> ? routerPrecondition}) -
const
Properties
- child → Widget
-
final
- create → B Function()
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
precondition
→ Precondition<
RouteData> ? -
finalinherited
- router → BlocRouter?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shouldNotify
→ UpdateShouldNotify<
B> ? -
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _BlocProviderState< B> -
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