### Consuming Generated Riverpod Provider in UI (Dart) Source: https://github.com/chaturadilan/riverpod_repo_generator/blob/main/README.md Shows an example of how to use `ref.watch` to consume a generated Riverpod provider (`repoDataGetCategoriesProvider`) within a Flutter widget. It demonstrates handling the asynchronous states (`loading`, `error`, `data`) provided by Riverpod's `AsyncValue`. ```Dart ref.watch(repoDataGetCategoriesProvider).when( loading: () => const CircularProgressIndicator(), error: (err, stack) => Text('Error: $err'), data: (categories) { return Text(categories.toString()); }, ``` -------------------------------- ### Defining Repository Interface, Implementation, and Provider (Dart) Source: https://github.com/chaturadilan/riverpod_repo_generator/blob/main/README.md Illustrates how to define an abstract repository class annotated with `@riverpodRepo` and its concrete implementation. It also shows the Riverpod provider responsible for providing an instance of the repository implementation. ```Dart // File data_repo.dart import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:riverpod_repo/annotations.dart'; part 'data_repo.g.dart'; part 'data_repo.repo.dart'; @Riverpod(keepAlive: true) RepoData repoData(RepoDataRef ref) => RepoDataImpl(); @riverpodRepo abstract class RepoData { Future> getBooks({String search = '', String categoryId = ''}); Future> getTopGenres(); Future> getTopBooksByGenre(String genreId, {String search = ''}); Future> getCategories({String search = ''}); } class RepoDataImpl implements RepoData { @override Future> getBooks({String search = '', String categoryId = ''}) { // The implementation logic should be written in this section } @override Future> getCategories({String search = ''}) { // The implementation logic should be written in this section } @override Future> getTopBooksByGenre(String genreId, {String search = ''}) { // The implementation logic should be written in this section } @override Future> getTopGenres() { // The implementation logic should be written in this section } } ``` -------------------------------- ### Including Generated Repository and Provider Files (Dart) Source: https://github.com/chaturadilan/riverpod_repo_generator/blob/main/README.md Specifies the part files that will be generated by the build runner for the repository interface and the Riverpod providers, enabling code generation. ```Dart part 'data_repo.g.dart'; part 'data_repo.repo.dart'; ``` -------------------------------- ### Generated Riverpod Providers from Repository Methods (Dart) Source: https://github.com/chaturadilan/riverpod_repo_generator/blob/main/README.md Displays the Riverpod providers automatically generated by the `riverpod_repo_generator`. Each provider corresponds to a method in the abstract repository class and uses the main repository provider (`repoDataProvider`) to access the underlying implementation. ```Dart // GENERATED CODE - DO NOT MODIFY BY HAND part of 'data_repo.dart'; // ************************************************************************** // RiverPodRepoGenerator // ************************************************************************** @riverpod Future> repoDataGetBooks(RepoDataGetBooksRef ref, {String search = '', String categoryId = ''}) { return ref.watch(repoDataProvider).getBooks( search: search, categoryId: categoryId, ); } @riverpod Future> repoDataGetTopGenres( RepoDataGetTopGenresRef ref, ) { return ref.watch(repoDataProvider).getTopGenres(); } @riverpod Future> repoDataGetTopBooksByGenre( RepoDataGetTopBooksByGenreRef ref, String genreId, {String search = ''}) { return ref.watch(repoDataProvider).getTopBooksByGenre( genreId, search: search, ); } @riverpod Future> repoDataGetCategories(RepoDataGetCategoriesRef ref, {String search = ''}) { return ref.watch(repoDataProvider).getCategories( search: search, ); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.