refresh<State> abstract method
Forces a provider to re-evaluate its state immediately, and return the created value.
This method is useful for features like "pull to refresh" or "retry on error", to restart a specific provider.
For example, a pull-to-refresh may be implemented by combining FutureProvider and a RefreshIndicator:
final productsProvider = FutureProvider((ref) async {
final response = await httpClient.get('https://host.com/products');
return Products.fromJson(response.data);
});
class Example extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final Products products = ref.watch(productsProvider);
return RefreshIndicator(
onRefresh: () => ref.refresh(productsProvider),
child: ListView(
children: [
for (final product in products.items) ProductItem(product: product),
],
),
);
}
}
Implementation
State refresh<State>(ProviderBase<State> provider);