I’m working on an app which has a mobile and a web app I have created my custom Nodejs APIs with the MYSQL database, the APIs are working fine in the mobile app. but in I case of flutter web, my post APIs are working fine but I cannot read data from the API, The API is working fine in postman also in the mobile app, but when I test it in flutter web
I got this error in response. [log] Error fetching products: ClientException: XMLHttpR…, uri=http://127.0.0.1:2000/api/v1/product/getall (using HTTP package)
I also tried the Dio package bit same error [log] Error fetching products: DioException [connection …hich most likely cannot be solved by the library.
here is my function to fetch data :
Future<List<Product>> fetchProducts() async {
log("hit");
final url = Uri.parse(
'$baseURL:2000/api/v1/product/getall'); // Replace with your local IP and port
try {
final response = await http.get(url);
if (response.statusCode == 200) {
final responseData = json.decode(response.body);
final List<dynamic> data = responseData['data'];
log('Response data: ${responseData['data']}');
return data
.map((productJson) => Product.fromJson(productJson))
.toList();
} else {
log('Failed to load products. Status code: ${response.statusCode}');
return [];
}
} catch (error) {
log('Error fetching products: $error');
return [];
}
}
NOTE: it works fine in Postman and mobile app, the issue is only in flutter web
I want to read data and show them in my web app