Skip to content

Instantly share code, notes, and snippets.

@Slowhand0309
Last active September 28, 2020 02:04
Show Gist options
  • Save Slowhand0309/c99d268ffd0bec1b89f5b70b1b29784d to your computer and use it in GitHub Desktop.
Save Slowhand0309/c99d268ffd0bec1b89f5b70b1b29784d to your computer and use it in GitHub Desktop.
[Riverpod FutureProvider] sample, links #Flutter

Document

https://pub.dev/documentation/riverpod/latest/all/FutureProvider-class.html

Sample

https://github.com/rrousselGit/river_pod/blob/bf1bca8f87beb819d0b10be9e45d01048c2a5505/packages/riverpod/example/lib/main.dart

final futureProvider1 = FutureProvider<Model>((_) async {
  final model = await AsyncFunc();
  return model;
});

final futureProvider2 = FutureProvider<Repository>((ref) async {
  final model = await ref.watch(futureProvider1.future);
  return Repository(model);
});

// main
final container = ProviderContainer();
final repository = await container.read(futureProvider2.future);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment