Skip to main content
movieRepositoryProvider is a Riverpod Provider that constructs the single shared instance of MovieRepositoryImpl for the entire widget tree. All movie-list providers depend on it to reach the TheMovieDB API.

Provider definition

movies_repository_provider.dart

Return type

movieRepositoryProvider is inferred as Provider<MovieRepositoryImpl>. Because MovieRepositoryImpl implements the abstract MoviesRepository contract, consumers only need to depend on the interface.

Dependency injection pattern

The provider uses constructor injection: MovieRepositoryImpl receives a MoviedbDataSource instance through its constructor. This creates a strict, one-directional dependency chain:
Neither the UI nor the notifiers need to know about MoviedbDataSource directly. They interact only through the MoviesRepository abstract interface, which makes it straightforward to swap the data source (e.g. a mock or a local cache) without touching any presentation code.

MovieRepositoryImpl

MovieRepositoryImpl implements every method declared in the MoviesRepository abstract class by delegating to the injected MoviesDatasource.
movie_repository_impl.dart

MoviesRepository abstract interface

The domain layer defines the contract that any repository implementation must fulfil. This keeps the presentation and domain layers free of infrastructure details.
movies_repository.dart

Reading the provider

Movie-list providers watch movieRepositoryProvider and pull individual method references from it:
movies_providers.dart
You can also read it directly in a widget when you need an ad-hoc call:
Use ref.read (not ref.watch) when calling the repository imperatively inside callbacks or initState. Reserve ref.watch for reactive rebuilds.