photos method

Request<SearchResults<Photo>> photos(
  1. String query, {
  2. int? page,
  3. int? perPage,
  4. Iterable<String>? collections,
  5. PhotoColor? color,
  6. PhotoOrientation? orientation,
  7. PhotoOrder? orderBy,
  8. ContentFilter? contentFilter,
  9. String? lang,
})

Search photos

Get a single page of photo results for a query.

The photo objects returned here are abbreviated. For full details use Photos.get.

See: Unsplash docs

Implementation

Request<SearchResults<Photo>> photos(
  String query, {
  int? page,
  int? perPage,
  Iterable<String>? collections,
  PhotoColor? color,
  PhotoOrientation? orientation,
  PhotoOrder? orderBy,
  ContentFilter? contentFilter,
  String? lang,
}) {
  assert(page == null || page >= 0);
  assert(perPage == null ||
      perPage >= 0 && perPage <= client.settings.maxPageSize);

  final params = queryParams({
    'query': query,
    'page': page,
    'per_page': perPage,
    'collections': collections?.join(','),
    'orientation': orientation?.let(enumName),
    'order_by': orderBy?.let(enumName),
    'color': color?.let(enumName),
    'content_filter': contentFilter?.let(enumName),
    'lang': lang,
  });

  final url = baseUrl.resolve('photos').replace(queryParameters: params);

  return Request(
    client: client,
    httpRequest: http.Request('GET', url),
    isPublicAction: true,
    bodyDeserializer: (dynamic json) => SearchResults.fromJson(
        json as Map<String, dynamic>, (json) => Photo.fromJson(json)),
  );
}