Allow customizing refresh on RFBPA
This commit is contained in:
parent
e19d761f4d
commit
aea7647c89
1 changed files with 4 additions and 3 deletions
|
@ -138,9 +138,10 @@ enum RefreshFutureBuilderState {
|
|||
|
||||
class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget {
|
||||
final Provider<AsyncValue<T>> futureProvider;
|
||||
final Future Function()? refresh;
|
||||
final Widget Function(BuildContext context, Future Function() refresh, Future Function(Future<T> Function()) replaceFuture, RefreshFutureBuilderSnapshot<T> snapshot) builder;
|
||||
|
||||
const RefreshFutureBuilderProviderAdapter({required this.futureProvider, required this.builder, super.key});
|
||||
const RefreshFutureBuilderProviderAdapter({required this.futureProvider, required this.builder, this.refresh, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
|
@ -148,7 +149,7 @@ class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget {
|
|||
|
||||
return builder(
|
||||
context,
|
||||
() async {
|
||||
refresh ?? () async {
|
||||
ref.invalidate(futureProvider);
|
||||
},
|
||||
(_) => throw UnimplementedError('Cannot replace the future when adapting a FutureProvider'),
|
||||
|
@ -157,7 +158,7 @@ class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget {
|
|||
? RefreshFutureBuilderSnapshot.refresh(data)
|
||||
: RefreshFutureBuilderSnapshot.withData(data),
|
||||
error: (error, st) => value.isLoading || value.isRefreshing
|
||||
? RefreshFutureBuilderSnapshot.refreshError(value.value, value.error, value.stackTrace)
|
||||
? RefreshFutureBuilderSnapshot.refreshError(value.hasValue ? value.value : null, value.error, value.stackTrace)
|
||||
: RefreshFutureBuilderSnapshot.withError(error, st),
|
||||
loading: () {
|
||||
if (value.hasValue) {
|
||||
|
|
Loading…
Add table
Reference in a new issue