PlConfirmProvider class
One dialog, asked for from anywhere under it.
The thing a caller has at the moment a question is warranted is a callback,
not a place in the tree — onPressed: () async { if (await …confirm(…)) … }
is the shape this exists to make possible. The alternative, and what every
application writes without it, is a piece of state per question plus a
PlModal kept in the tree beside every button that might need one, and the
branch after the answer torn in half across a callback.
It is PlToastProvider's arrangement for the same reason and with the same trade: one widget high in the tree, and a lookup everywhere else.
It goes inside the application rather than around it, because above a
WidgetsApp or a MaterialApp there is no Directionality yet. builder
is the place, and what builder returns sits above the navigator and the
navigator's Overlay — so the dialog needs one of its own, or confirm
fails with "No Overlay widget found".
WidgetsApp(
// …
builder: (BuildContext context, Widget? child) =>
Overlay.wrap(child: PlConfirmProvider(child: child!)),
)
if (await PlConfirmProvider.of(context).confirm(
const PlConfirmOptions(title: Text('Delete this project?'), color: PlassColor.danger),
)) {
await remove(project);
}
Questions asked while one is open are queued, in the order they were asked. The alternative is a future nobody ever completes, which is a hung button rather than a visible bug.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- PlConfirmProvider
Constructors
- PlConfirmProvider({required Widget child, Widget? confirmLabel, Widget? cancelLabel, Widget? acknowledgeLabel, double? width, PlassSize? size, PlassColor? color, Key? key})
-
Creates a provider.
const
Properties
- acknowledgeLabel → Widget?
-
The default word on an
alert's single button. Falls back to the label pack'sacknowledge.final - cancelLabel → Widget?
-
The default word on the button that answers no. Falls back to the label
pack's
cancel.final - child → Widget
-
The application.
final
- color → PlassColor?
-
The default family the confirming button takes.
final
- confirmLabel → Widget?
-
The default word on the button that answers yes. Falls back to the label
pack's
confirm.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
- size → PlassSize?
-
The default size of a question.
final
- width → double?
-
How wide a sheet may get, unless a question says otherwise.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< PlConfirmProvider> -
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, int wrapWidth = 65}) → 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(
BuildContext context) → PlConfirmController? - The same, without the assertion.
-
of(
BuildContext context) → PlConfirmController -
The controller for the nearest provider above
context.