buildUrl method

String buildUrl({
  1. required Location location,
  2. DateTime? timestamp,
  3. String? language,
})

Implementation

String buildUrl({
  required Location location,
  DateTime? timestamp,
  String? language,
}) {
  timestamp ??= DateTime.now();

  final params = <String, String>{
    'location': location.toString(),
    'timestamp': (timestamp.millisecondsSinceEpoch ~/ 1000).toString(),
  };

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

  if (apiKey != null) {
    params.putIfAbsent('key', () => apiKey!);
  }

  return url.replace(queryParameters: params).toString();
}