Last active
August 18, 2022 14:37
-
-
Save gausoft/04371faeb47db31483fd3e9b7cd1693b to your computer and use it in GitHub Desktop.
Expose data with riverpod's simple Provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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