async_value_group
async_value_group copied to clipboard
Features
async_value_group is a a Dart library for grouping some riverpod AsyncValues into single AsyncValue.
- Grouping some
AsyncValues into singleAsyncValueand retrieve allAsyncValue.dataas a tuple. - Waiting to be done multiple asynchronous process.
- If you use hooks_riverpod, call
AsyncValue.whenonly once inWidget.buildmethod even if multiple AsyncValues are required.
Usage
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:async_value_group/async_value_group.dart';
class TweetsPage extends HookConsumerWidget {
const TweetsPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
return AsyncValueGroup.group2(
ref.watch(tweetsProvider),
ref.watch(userProvider),
).when(
data: (t) => t.$1.isEmpty ? const TweetsEmpty() : TweetsBody(tweets: t.$1, user: t.$2),
error: (error, st) => ErrorPage(error: error),
loading: () => const Loading(),
);
}
}