Show loading on refresh provider #3892
Answered
by
snapsl
samanzamani
asked this question in
Q&A
-
Hi Switch method_Loading just shows in the init state and doesn't show on refresh @riverpod
class PackageViewModel extends _$PackageViewModel {
@override
Future<PackageListEntity> build() async {
// fetch data from network and return
}
}
class BuyPackagePage extends HookConsumerWidget {
const BuyPackagePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<PackageListEntity> viewModel =
ref.watch(packageViewModelProvider);
return switch (viewModel) {
AsyncData(:final value) => _Content(packageListEntity: value),
AsyncError() => _Error(onRetry: () {
ref.invalidate(packageViewModelProvider);
})),
_ => const _Loading(),
};
}
} When method_Loading shows in the init and refresh states @riverpod
class PackageViewModel extends _$PackageViewModel {
@override
Future<PackageListEntity> build() async {
// fetch data from network and return
}
}
class BuyPackagePage extends HookConsumerWidget {
const BuyPackagePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<PackageListEntity> viewModel =
ref.watch(packageViewModelProvider);
return viewModel.when(
skipLoadingOnReload: false,
skipLoadingOnRefresh: false,
data: (value) => _Content(packageListEntity: value),
error: (_, __) =>
_Error(onRetry: () {
ref.invalidate(packageViewModelProvider);
}
),
loading: () => const _Loading()
);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
snapsl
Dec 26, 2024
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
samanzamani
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AsyncError
needs arguments. Use it like this.