`
Future<void> fetchData() async {
final String apiUrl = 'http://192.168.100.90:4002/booking/getall';
try {
// Making GET request
final response = await http.get(Uri.parse(apiUrl));
print(response.statusCode);
// Decoding response
if (response.statusCode == 200) {
// If the server returns a 200 OK response,
// parse the JSON
final Map<String, dynamic> responseData = json.decode(response.body);
// Process the data here if needed
print(responseData);
} else {
// If the server did not return a 200 OK response,
// throw an exception
throw Exception('Failed to load data');
}
} catch (e) {
// Error handling
print('Error: $e');
throw e;
}
}
`
I/flutter ( 2707): Error: ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110), address = 192.168.100.90, port = 48130, uri=http://192.168.100.90:4002/booking/getall
E/flutter ( 2707): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110), address = 192.168.100.90, port = 48130, uri=http://192.168.100.90:4002/booking/getall
I am trying to connect my API to my flutter application and I am finding a solution of this error. what should i do now
This error occurs because the port emulator can read/write(CRUD) and your server's actual port where the server is running on (For local dev machine only) is not the same.
Change the URL on your Flutter project code to this.
To
And make sure you have provided the internet permission on the manifest