riverpod_repo 5.1.0 copy "riverpod_repo: ^5.1.0" to clipboard
riverpod_repo: ^5.1.0 copied to clipboard

Generate Riverpod FutureProvider, StreamProvider, and Provider declarations from repository interfaces using the repository pattern.

example/example.dart

import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:riverpod_repo/annotations.dart';

import 'country.dart';
import 'student.dart';

part 'example.g.dart';

@Riverpod(keepAlive: true)
RepoData repoData(Ref ref) => RepoDataImpl();

@RiverpodRepoAnnotation(keepAlive: true)
/// Repository class to get Data
abstract class RepoData {
  /// Get the books
  Future<List<Student>> getBooks({String search = '', String categoryId = ''});

  /// Get the top  genres (auto-dispose overrides class keepAlive)
  @RepoQueryAnnotation(keepAlive: false)
  Future<List<int>> getTopGenres();

  /// Get the top books by genre
  Future<List<bool>> getTopBooksByGenre(String genreId, {String search = ''});

  Future<List<Hello>> getCategories({String search = ''});

  /// Get the country by code
  Future<Country> getCountry(String code);

  /// Mutation — no provider is generated
  Future<void> deleteBook(String bookId);
}

/// Repository Implementation class to get Data
class RepoDataImpl implements RepoData {
  /// Implimentation of the getBooks method
  @override
  Future<List<Student>> getBooks({String search = '', String categoryId = ''}) {
    throw UnimplementedError();
  }

  /// Implimentation of the getCategories method
  @override
  Future<List<Hello>> getCategories({String search = ''}) {
    throw UnimplementedError();
  }

  /// Implimentation of the getTopBooksByGenre method
  @override
  Future<List<bool>> getTopBooksByGenre(String genreId, {String search = ''}) {
    throw UnimplementedError();
  }

  /// Implimentation of the getTopGenres method
  @override
  Future<List<int>> getTopGenres() {
    throw UnimplementedError();
  }

  /// Implimentation of the getCountry method
  @override
  Future<Country> getCountry(String code) {
    throw UnimplementedError();
  }

  @override
  Future<void> deleteBook(String bookId) {
    throw UnimplementedError();
  }
}
8
likes
160
points
343
downloads

Documentation

Documentation
API reference

Publisher

verified publisherdilexus.dev

Weekly Downloads

Generate Riverpod FutureProvider, StreamProvider, and Provider declarations from repository interfaces using the repository pattern.

Homepage
Repository (GitHub)
View/report issues

Topics

#riverpod #code-generation #repository-pattern #flutter #dart

License

MIT (license)

Dependencies

analyzer, build, recase, riverpod, riverpod_annotation, source_gen

More

Packages that depend on riverpod_repo