getPublicIPAddress method

Future<String?> getPublicIPAddress()

Implementation

Future<String?> getPublicIPAddress() async {
  try {
    final response = await http.get(Uri.parse('https://api.ipify.org'));
    if (response.statusCode == 200) {
      //print('deviceIpAddrs>>${response.body}');

      return response.body;
    } else {
      // Handle error response
      // print('Failed to get public IP: ${response.statusCode}');
      return null;
    }
  } catch (e) {
    // Handle network or other errors
    // print('Error fetching public IP: $e');
    return null;
  }
}