getData static method

Future<GeolocationData> getData({
  1. String query = '',
})

Implementation

static Future<GeolocationData> getData({String query = ''}) async {
  try {
    final response = await http.get(Uri.parse("http://ip-api.com/json/$query"));
    if (response.statusCode == 200) {
      print(response.body);
      final parsed = jsonDecode(response.body);
      return GeolocationData.fromJson(parsed);
    }
    print("geolocation api ${response.statusCode}");
    return GeolocationData();
  } catch (e) {
    print(e);
    return GeolocationData();
  }
}