async_value_group is a a Dart library for grouping some riverpod AsyncValue
s into single AsyncValue
.
- Grouping some
AsyncValue
s into singleAsyncValue
and retrieve allAsyncValue.data
as a tuple. - Waiting to be done multiple asynchronous process.
- If you use hooks_riverpod, call
AsyncValue.when
only once inWidget.build
method even if multiple AsyncValues are required.
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(),
);
}
}