Created
November 28, 2024 17:31
-
-
Save vbalagovic/e1101ed4728942b29356abbd02970cbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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