buildTextSearchUrl method

String buildTextSearchUrl({
  1. required String query,
  2. Location? location,
  3. num? radius,
  4. PriceLevel? minprice,
  5. PriceLevel? maxprice,
  6. bool opennow = false,
  7. String? type,
  8. String? pagetoken,
  9. String? language,
  10. String? region,
})

Implementation

String buildTextSearchUrl({
  required String query,
  Location? location,
  num? radius,
  PriceLevel? minprice,
  PriceLevel? maxprice,
  bool opennow = false,
  String? type,
  String? pagetoken,
  String? language,
  String? region,
}) {
  final params = <String, String>{
    'query': query,
  };

  if (minprice != null) {
    params['minprice'] = minprice.index.toString();
  }

  if (maxprice != null) {
    params['maxprice'] = maxprice.index.toString();
  }

  if (opennow) {
    params['opennow'] = opennow.toString();
  }

  if (type != null) {
    params['type'] = type;
  }

  if (pagetoken != null) {
    params['pagetoken'] = pagetoken;
  }

  if (language != null) {
    params['language'] = language;
  }

  if (region != null) {
    params['region'] = region;
  }

  if (location != null) {
    params['location'] = location.toString();
  }

  if (radius != null) {
    params['radius'] = radius.toString();
  }

  if (apiKey != null) {
    params['key'] = apiKey!;
  }

  return url
      .replace(
        path: '${url.path}$_textSearchUrl',
        queryParameters: params,
      )
      .toString();
}