DefaultLoaderBuilder class

A Widget that makes it easier to use LoaderBuilder by providing different WidgetBuilder for different states in the loader's lifecycle.

{@tool snippet}

Example of a simple DefaultLoaderBuilder:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Flutter Loader Demo'),
    ),
    body: DefaultLoaderBuilder(
      themeData: DefaultLoaderThemeData(
        errorMessageResolver: (error) =>
        'Custom errorMessageResolver: $error',
      ),
      loader: () => Future.delayed(
        Duration(seconds: 3),
            () => 'Hello World',
      ),
      loadedBuilder: (context) {
        return Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('${LoaderController.of(context).data}'),
              SizedBox(height: 10),
              ElevatedButton(
                onPressed: () => LoaderController.of(context).load(
                      () => Future.delayed(
                      Duration(seconds: 3), () => Future.error('Oops')),
                ),
                child: Text('Error'),
              ),
              ElevatedButton(
                onPressed: () => LoaderController.of(context).load(),
                child: Text('Success'),
              ),
            ],
          ),
        );
      },
    ),
  );
}

{@end-tool}

Inheritance

Constructors

DefaultLoaderBuilder({Key? key, required FutureProvider loader, WidgetBuilder? initBuilder, WidgetBuilder? loadingBuilder, WidgetBuilder? errorBuilder, WidgetBuilder? loadedBuilder, void onControllerCreated(LoaderController controller)?, void onError(dynamic error, StackTrace stackTrace)?, DefaultLoaderThemeData? themeData, bool autoLoad = true})
Creates a DefaultLoaderBuilder to handle resource loading using loader and show according UI for different state.

Properties

autoLoad bool
Whether the loader will load the data automatically in the beginning
final
errorBuilder WidgetBuilder?
Builds widget for the state of LoaderState.error. Omit to use defaultErrorWidget.
final
hashCode int
The hash code for this object.
no setterinherited
initBuilder WidgetBuilder?
Builds widget for the state of LoaderState.init. Omit to use defaultInitWidget.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadedBuilder WidgetBuilder?
Builds widget for the state of LoaderState.loaded. Omit to use defaultLoadedWidget.
final
loader FutureProvider
Provides a Future which will do the actual work for loading data.
final
loadingBuilder WidgetBuilder?
Builds widget for the state of LoaderState.loading. Omit to use defaultLoadingWidget.
final
onControllerCreated → (void Function(LoaderController controller)?)
Callback function which will be called right after the controller is created.
final
onError → (void Function(dynamic error, StackTrace stackTrace)?)
Callback function which will be called when the error occurs.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
themeData DefaultLoaderThemeData?
Visual configuration for the default UI implementations.
final

Methods

build(BuildContext _) 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 Methods

defaultErrorWidget(BuildContext context) Widget
Default UI for LoaderState.error.
defaultInitWidget(BuildContext context) Widget
Default UI for LoaderState.init.
defaultLoadedWidget(BuildContext context) Widget
Default UI for LoaderState.loaded.
defaultLoadingWidget(BuildContext context) Widget
Default UI for LoaderState.loading.