Skip to content

Instantly share code, notes, and snippets.

@vishalbandre
Created September 25, 2020 07:28
Show Gist options
  • Save vishalbandre/52592a434b7c1dbd9c7492790bfef5f7 to your computer and use it in GitHub Desktop.
Save vishalbandre/52592a434b7c1dbd9c7492790bfef5f7 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:http/http.dart' as http;
class Example {
Future<String> _getIPAdress() {
final url = 'https://httpbin.org/ip';
return http.get(url).then(response) {
String ip = jsonDecode(response.body)['origin'];
return ip;
}
}
}
main() {
final example = new Example();
example
._getIPAddress()
.then((ip)) => print(ip)
.catchError((error) => print(error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment