AdvancedUserException class

Extends the UserException to add more features.

The AdvancedUserException is not supposed to be instantiated directly. Instead, use the addCallbacks, addCause and addProps extension methods in the UserException:

UserException(message, code: code, reason: reason)
   .addCallbacks(onOk: onOk, onCancel: onCancel)
   .addCause(cause)
   .addProps(props);

Example:

throw UserException('Invalid number', reason: 'Must be less than 42')
   .addCallbacks(onOk: () => print('OK'), onCancel: () => print('CANCEL'))
   .addCause(FormatException('Invalid input'))
   .addProps({'number': 42}));

When the exception is shown to the user in the UserExceptionDialog, if callbacks onOk and onCancel are defined, the dialog will have OK and CANCEL buttons, and the callbacks will be called when the user taps them.

The hardCause is some error which caused the UserException.

The props are any key-value pair properties you'd like to add to the exception.

Inheritance
Implementers
Available Extensions
Annotations

Constructors

AdvancedUserException(String? message, {required String? reason, required int? code, required String? errorText, required bool ifOpenDialog = true, required VoidCallback? onOk, required VoidCallback? onCancel, required Object? hardCause, IMap<String, dynamic> props = const IMapConst<String, dynamic>({})})
Instead of using this constructor directly, prefer doing:
const

Properties

code int?
Optionally, instead of message we may provide a numeric code. This code may have an associated message which is set in the client.
finalinherited
errorText String?
Some text to be displayed in the UI element that is responsible for the error. For example, a text field could show this text in its errorText property. When building your widgets, you can get the errorText from the failed action: String errorText = context.exceptionFor(MyAction)?.errorText.
finalinherited
hardCause Object?
The hard cause is some error which caused the UserException, but that is not a UserException itself. For example: int.parse('a') throws a FormatException. Then: throw UserException('Invalid number').addCause(FormatException('Invalid input')). will have the FormatException as the hard cause. Note: If a UserException is passed as the hard cause, it will be added with addCause, and will not become the hard cause. In other words, a UserException will never be a hard cause.
final
hashCode int
The hash code for this object.
no setteroverride
ifOpenDialog bool
If true, the UserExceptionDialog will show in the dialog or similar UI. If false you can still show the error in a different way, usually showing errorText in the UI element that is responsible for the error.
finalinherited
message String?
Some message shown to the user.
finalinherited
noDialog UserException
no setterinherited
onCancel VoidCallback?
Callback to be called after the user views the error, and taps CANCEL in the dialog.
final
onOk VoidCallback?
Callback to be called after the user views the error, and taps OK in the dialog.
final
props → IMap<String, dynamic>
The properties added to the exception, if any. They are an immutable-map of type IMap, of key-value pairs. To read the properties, use the [] operator, like this:
final
reason String?
Another text which is the reason of the user-exception.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addReason(String? reason) UserException
Returns a new UserException, copied from the current one, but adding the given reason. Note the added reason won't replace the original reason, but will be added to it.
override
mergedWith(UserException? anotherUserException) UserException
Returns a new UserException, by merging the current one with the given anotherUserException. This simply means the given anotherUserException will be used as part of the reason of the current one.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
titleAndContent() → (String, String)
Based on the message, code and reason, returns the title and content to be used in some UI to show the exception the user. The UI is usually a dialog or toast.
inherited
toString() String
A string representation of this object.
override
withDialog(bool ifOpenDialog) UserException
Defines if this exception should open a dialog or not. If not, it will be shown in a different way, usually showing errorText somewhere in the UI.
override
withErrorText(String? newErrorText) UserException
Adds (or replaces, if it already exists) the given newErrorText. If the newErrorText is null or empty, it will remove the errorText.
override

Operators

operator ==(Object other) bool
The equality operator.
override