Skip to content

Instantly share code, notes, and snippets.

@vbalagovic
Created November 28, 2024 17:31
Show Gist options
  • Save vbalagovic/e1101ed4728942b29356abbd02970cbb to your computer and use it in GitHub Desktop.
Save vbalagovic/e1101ed4728942b29356abbd02970cbb to your computer and use it in GitHub Desktop.
@riverpod
class MovieService extends _$MovieService {
late final _dio = Dio(
BaseOptions(
baseUrl: 'https://6748a43f5801f5153591b589.mockapi.io/api',
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 3),
),
);
@override
Future<List<Movie>> build() async {
return fetchMovies();
}
Future<List<Movie>> fetchMovies([String filter = ""]) async {
final response = await _dio.get('/movies', queryParameters: {
if (filter.isNotEmpty) 'Title': filter,
});
return (response.data as List).map((json) => Movie.fromJson(json)).toList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment