future property

A provider that exposes the Future created by a FutureProvider.

The instance of Future obtained may change over time, if the provider was recreated (such as when using ProviderReference.watch).

This provider allows using async/await to easily combine FutureProvider together:

final configsProvider = FutureProvider((ref) async => Configs());

final productsProvider = FutureProvider((ref) async {
  // Wait for the configurations to resolve
  final configs = await ref.watch(configsProvider.future);

  // Do something with the result
  return await http.get('${configs.host}/products');
});

Implementation

AlwaysAliveProviderBase<Future<T>, Future<T>> get future {
  return _future ??= CreatedProvider(
    this,
    name: name == null ? null : '$name.future',
  );
}