Pottery class
A widget that controls the availability of particular pots according to the widget lifecycle.
The factory of the ReplaceablePot specified as the key in the map (pots) is replaced with the PotObjectFactory specified as its value. An existing object is also replaced immediately with a new one created by the new factory if one has already existed. If there was no object, a new one is not created soon but only when it is accessed for the first time.
If the pottery is removed from the tree permanently, the object is discarded and the factory is removed. After the removal, trying to access the object throws PotNotReadyException.
final notesNotifierPot = Pot.pending<NotesNotifier>(
disposer: (notifier) => notifier.dispose(),
);
final notesRepositoryPot = Pot.pending<NotesRepository>(
disposer: (repository) => repository.dispose(),
);
...
child: Pottery(
pots: {
notesNotifierPot: NotesNotifier.new,
notesRepositoryPot: NotesRepository.new,
},
builder: (context) {
return ChildWidget();
},
),
Note that Pottery does not bind pots to the widget tree. It only uses the lifecycle of itself in the tree to control the lifespan of pots' content, which is an important difference from LocalPottery.
Also note that an error arises only at runtime if the map contains wrong pairs of pot and factory. Make sure to specify a correct factory creating an object of the right type.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Pottery
Constructors
- Pottery({Key? key, required PotReplacements pots, required WidgetBuilder builder})
-
Creates a Pottery widget that limits the lifespan of the
factory and the object of particular Pots according to
its own lifespan.
const
Properties
- builder → WidgetBuilder
-
A function called to obtain the child widget.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- pots → PotReplacements
-
A map of replaceable pots and factories.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Pottery> -
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
-
startExtension(
) → void - Starts the DevTools extension manually.