Skip to content

Instantly share code, notes, and snippets.

@gausoft
Last active August 18, 2022 14:37
Show Gist options
  • Save gausoft/04371faeb47db31483fd3e9b7cd1693b to your computer and use it in GitHub Desktop.
Save gausoft/04371faeb47db31483fd3e9b7cd1693b to your computer and use it in GitHub Desktop.
Expose data with riverpod's simple Provider
// Example 01 : Simple scallar type
final valueProvider = Provider<int>((ref) {
return 36;
});
// Example 02
final databaseProvider = Provider((ref) => Database());
// Example 03 : Real class as dependency injection
final httpClientProvider = Provider<Dio>((ref) => Dio());
final productRepositoryProvider = Provider<ProductRepository>(
(ref) {
final httpClient = ref.watch(httpClientProvider);
return ProductRepositoryImpl(httpClient);
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment