|
|
@ -138,9 +138,10 @@ enum RefreshFutureBuilderState { |
|
|
|
|
|
|
|
|
|
|
|
class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget { |
|
|
|
class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget { |
|
|
|
final Provider<AsyncValue<T>> futureProvider; |
|
|
|
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; |
|
|
|
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 |
|
|
|
@override |
|
|
|
Widget build(BuildContext context, WidgetRef ref) { |
|
|
|
Widget build(BuildContext context, WidgetRef ref) { |
|
|
@ -148,7 +149,7 @@ class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget { |
|
|
|
|
|
|
|
|
|
|
|
return builder( |
|
|
|
return builder( |
|
|
|
context, |
|
|
|
context, |
|
|
|
() async { |
|
|
|
refresh ?? () async { |
|
|
|
ref.invalidate(futureProvider); |
|
|
|
ref.invalidate(futureProvider); |
|
|
|
}, |
|
|
|
}, |
|
|
|
(_) => throw UnimplementedError('Cannot replace the future when adapting a FutureProvider'), |
|
|
|
(_) => throw UnimplementedError('Cannot replace the future when adapting a FutureProvider'), |
|
|
@ -157,7 +158,7 @@ class RefreshFutureBuilderProviderAdapter<T> extends ConsumerWidget { |
|
|
|
? RefreshFutureBuilderSnapshot.refresh(data) |
|
|
|
? RefreshFutureBuilderSnapshot.refresh(data) |
|
|
|
: RefreshFutureBuilderSnapshot.withData(data), |
|
|
|
: RefreshFutureBuilderSnapshot.withData(data), |
|
|
|
error: (error, st) => value.isLoading || value.isRefreshing |
|
|
|
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), |
|
|
|
: RefreshFutureBuilderSnapshot.withError(error, st), |
|
|
|
loading: () { |
|
|
|
loading: () { |
|
|
|
if (value.hasValue) { |
|
|
|
if (value.hasValue) { |
|
|
|