riverpod_async_value_widget

GitHub Pub Version Style

Used to simplify the display of AsyncValues from Riverpod.

Usage

The basic purpose of the package is to save you from having to create error/loading states every time you want to display an AsyncValue. The AsyncValueWidget automatically shows a progress indicator in the loading state, and an error message in the error state.

A "Retry" button can be added by specifying an onRetry callback.

@override
Widget build(BuildContext context, WidgetRef ref) {
    final myValue = ref.watch(myProvider);

    return AsyncValueWidget<String>(
        value: myValue,
        builder: (context, data) {
            return Text(data);
        },
        onRetry: () => ref.refresh(myProvider),
    );
}

Customisation

There is a variety of customisation options available in AsyncValueWidget. Many of these options can be applied globally (or for any other widget tree scope) using the DefaultAsyncValueWidgetConfig widget:

DefaultAsyncValueWidgetConfig(
    transitionDuration: const Duration(milliseconds: 50),
    // Lots of other options available
    child: MyApp(),
);