Superpowers class
A widget that enables context.isWaiting, context.isFailed, and
context.getException to trigger widget rebuilds when method state changes.
Place this widget near the top of your widget tree, typically wrapping your MaterialApp or CupertinoApp:
void main() {
runApp(
Superpowers(
child: MaterialApp(
home: UserExceptionDialog(
child: MyHomePage(),
),
),
),
);
}
Then in your widgets, simply use the context extensions:
Widget build(BuildContext context) {
if (context.isWaiting(FetchUserAction)) return CircularProgressIndicator();
if (context.isFailed(FetchUserAction)) return Text('Error: ${context.getException(FetchUserAction)?.message}');
return UserProfile();
}
You can also check multiple method types:
if (context.isWaiting([FetchUserAction, FetchPostsAction])) {
return CircularProgressIndicator();
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Superpowers
Constructors
- Superpowers({required Widget child, Key? key})
-
Creates a Superpowers widget with the given
child.const
Properties
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Superpowers> -
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 Properties
-
errors
→ Queue<
UserException> -
Returns a copy of the error queue (read-only).
no setter
- globalCatchError ↔ void Function(Object error, StackTrace stackTrace, Object key)?
-
Global error handler called after all local
catchErrorhandlers.getter/setter pair - observer ↔ void Function(bool isStart, Object key, Object? metrics, Object? error, StackTrace? stackTrace, Duration? duration)?
-
Global observer for mix calls, useful for metrics and analytics.
getter/setter pair
-
onStateChange
→ Stream<
void> -
Stream that emits when method waiting/failed state changes.
no setter
-
onUserException
→ Stream<
UserException> -
Stream of UserExceptions for UI to listen to.
Use this with UserExceptionDialog to show error dialogs.
no setter
- simulateInternet → bool?
-
Returns the simulated internet state for use by connectivity checks.
no setter
Static Methods
-
addUserException(
UserException error) → void - Adds a UserException to the error queue. This is also used by the standalone retry function.
-
clear(
{int maxErrorsQueued = 10, bool? simulateInternet()?}) → void - Clears Superpowers static configuration. This is generally used to reset between tests, and it's not necessary to call it in production.
-
clearErrors(
) → void - Clears all errors from the queue.
-
clearException(
Object keyOrList) → void - Clears the failed state for the given mix key(s).
-
disposeProp(
Object? keyToDispose) → void - Disposes a single property identified by its key and removes it from props.
-
disposeProps(
[bool predicate({Object? key, Object? value})?]) → void - Disposes and removes properties from the store.
-
getAndRemoveFirstError(
) → UserException? - Gets and removes the first error from the queue. Returns null if the queue is empty.
-
getException(
Object keyOrList) → UserException? - Returns the UserException for a failed mix call, or null.
-
isFailed(
Object keyOrList) → bool - Returns true if a mix call with the given key has failed.
-
isWaiting(
Object keyOrList) → bool - Returns true if a mix call with the given key(s) is currently in progress.
-
onComplete(
Object key, UserException? error) → void - Called when a mix function call with a key FINISHES executing. Used internally by mix. Use isWaiting to check the state.
-
onStart(
Object key) → void - Called when a mix function call with a key STARTS executing. Used internally by mix. Use isWaiting to check the state.
-
prepareToLogout(
{Duration delay = const Duration(seconds: 5)}) → Future< void> - Resets user-specific state while keeping app-level configuration.
-
prop<
V> (Object? key) → V - Gets a property from the store.
-
setProp(
Object? key, Object? value) → void - Sets a property in the store.