getMediaList method

Future<List<Media>> getMediaList({
  1. int page = 1,
  2. int perPage = 20,
})

Retrieves a list of media attachments from the API.

page - The page number of the emdia list to retrieve. Defaults to 1. perPage - The number of media items to retrieve per page. Defaults to 20.

Returns a list of consultation objects if the API call is successful.

Implementation

Future<List<Media>> getMediaList(
    {int page = 1, int perPage = 20}) async {
  final response = await callApi(
      perPage: perPage,
      page: page,
      endpoint: 'media',
      method: 'get');

  if (response.statusCode == 200) {
    final List<dynamic> responseData = json.decode(response.body);
    final List<Media> mediaList =
    responseData.map((json) => Media.fromJson(json)).toList();
    return mediaList;
  } else {
    throw Exception('Error: ${response.body}');
  }
}