ErrorCardWidget class

ErrorCardWidget is an error widget presenting an error as a widget. It provides an option to display a retry button in case the user wants to repeat an operation.

A text or an exception must be provided in order for the error to be displayed. In case an exception is provided, the message can be customized with the exceptionTextBuilder which takes the exception and returns a string which can be customized.

You can also specify the errorMessageBuilder static function which will be used for converting all exceptions to string, in case you don't want to define specific exceptionTextBuilders for each widget. The function will be used on an app level and will not be applied if an exceptionTextBuilder is defined for the widget.

An optional header widget can be provided which will be displayed above the message which will replace the default error icon.

In case you want to display a retry button, you can do that by setting the retryButtonVisible flag to true. You can customize the text and color of the retry button by providing a retryButtonText and a retryButtonColorStyle for the widget.

Once the button is pressed, the onRetryPressed callback is executed. Also, you can set the state of the button with the retryButtonState in case you want to disable it or display an inactive state.

Inheritance

Constructors

ErrorCardWidget({String? text, Exception? exception, String exceptionTextBuilder(BuildContext, Exception)?, Widget? header, VoidCallback? onRetryPressed, ButtonColorStyle? retryButtonColorStyle, String retryButtonText = 'Retry', bool retryButtonVisible = false, ButtonStateModel retryButtonState = ButtonStateModel.enabled, MainAxisAlignment verticalAxisAlignment = MainAxisAlignment.start, Key? key})
const

Properties

exception Exception?
An exception to be displayed, if no text is provided
final
exceptionTextBuilder String Function(BuildContext, Exception)?
A builder function which converts an exception into a presentable string
final
hashCode int
The hash code for this object.
no setterinherited
The header widget displayed above the error
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onRetryPressed VoidCallback?
The callback executed once the retry button has been pressed
final
retryButtonColorStyle ButtonColorStyle?
The color style of the retry button
final
retryButtonState ButtonStateModel
The state of the retry button
final
retryButtonText String
The text displayed on the retry button
final
retryButtonVisible bool
Flag indicating whether or not to display the retry button
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
text String?
The text to be displayed, if no exception is provided
final
verticalAxisAlignment MainAxisAlignment
The vertical alignment of the contents of the widget
final

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}) 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

errorMessageBuilder String Function(BuildContext, Exception)?
Static function which translates an exception and returns a string. Useful in case you want to define a single function and use it throughout the app
getter/setter pair