A reactive caching and data-binding framework.https://riverpod.dev Riverpod makes working with asynchronous code a breeze by:
- handling errors/loading states by default. No need to manually catch errors
- natively supporting advanced scenarios, such as pull-to-refresh
- separating the logic from your UI
- ensuring your code is testable, scalable and reusable
riverpod | |
---|---|
flutter_riverpod | |
hooks_riverpod |
Welcome toRiverpod(anagram ofProvider)!
For learning how to useRiverpod,see its documentation: >>>https://riverpod.dev<<<
Long story short:
-
Define network requests by writing a function annotated with
@riverpod
:@riverpod Future<String>boredSuggestion(BoredSuggestionRefref)async{ finalresponse=awaithttp.get( Uri.https('boredapi.com','/api/activity'), ); finaljson=jsonDecode(response.body); returnjson['activity']!asString; }
-
Listen to the network request in your UI and gracefully handle loading/error states.
classHomeextendsConsumerWidget{ @override Widgetbuild(BuildContextcontext,WidgetRefref) { finalboredSuggestion=ref.watch(boredSuggestionProvider); // Perform a switch-case on the result to handle loading/error states returnswitch(boredSuggestion) { AsyncData(:finalvalue)=>Text('data: $value'), AsyncError(:finalerror)=>Text('error: $error'), _=>constText('loading'), }; } }
Contributions are welcome!
Here is a curated list of how you can help:
- Report bugs and scenarios that are difficult to implement
- Report parts of the documentation that are unclear
- Fix typos/grammar mistakes
- Update the documentation or add examples
- Implement new features by making a pull-request