PushPrompt class
The push permission soft prompt.
A single row explaining what push notifications buy the user and asking
for them BEFORE the platform's own one-shot prompt is spent. Presentational
on purpose: it renders the reachability and action it is handed and
reports the two decisions back, so its whole surface is reachable from a
widget test. PushPromptHost is the half that asks
Notify.manager.pushPromptAdvice() what this device's state actually is.
Why it takes an action as well as a reachability
Reachability alone cannot name a presentation. A blocked device on mobile
still has a route back (Notify.openPushSettings() opens the app's own
notification settings page), and a blocked browser has none, because no web
API opens the site settings panel from a page. That split is a property of
the PLATFORM, not of the reading, and the package answers it in
PushPromptAction rather than leaving each consumer to guess.
The four presentations
unavailable(PushPromptAction.none): this build has no push driver at all. One muted line.blocked: the OS prompt is spent. With PushPromptAction.openSettings the row keeps a real control that opens the platform setting; with PushPromptAction.instructions there is nowhere to send a tap, so it says where the switch lives instead of offering a control that silently does nothing.off(PushPromptAction.request): a real dialog will appear. Not yet resolved (declined false) shows the soft prompt with an explicit decline; a resolved ask (declined true) leaves the compact enable control, because a declined soft prompt must never be a dead end.on(PushPromptAction.none): subscribed. One confirming line.
Example Usage:
final advice = await Notify.manager.pushPromptAdvice();
PushPrompt(
reachability: advice.reachability,
action: advice.action,
// Two different calls: the request raises the dialog, the other opens
// the settings page directly.
onEnable: advice.action == PushPromptAction.openSettings
? () => Notify.openPushSettings()
: () => Notify.requestPushPermission(),
onDecline: () => myVault.recordDecline(),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- PushPrompt
- Annotations
Constructors
-
PushPrompt({Key? key, required PushReachability reachability, required PushPromptAction action, bool declined = false, bool busy = false, Future<
void> onEnable()?, VoidCallback? onDecline}) -
Creates a PushPrompt for the given
reachabilityandaction.const
Properties
- action → PushPromptAction
-
What this row's control can actually accomplish here, as
Notify.manager.pushPromptAdvice()resolved it.final - busy → bool
-
Whether an enable request is in flight, driving the button's spinner.
final
- declined → bool
-
Whether the soft ask has already been resolved on this device.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onDecline → VoidCallback?
-
Invoked when the user declines the soft prompt.
final
-
onEnable
→ Future<
void> Function()? -
Invoked when the user asks for push. The caller owns the platform
request; this widget never touches the SDK.
final
- reachability → PushReachability
-
Whether push can reach this device right now, as the platform reports it.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
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
Constants
-
blockedInstructionKey
→ const ValueKey<
String> - Identifies the instruction row a blocked device with no route back gets.