I have this error while connecting to a MySQL database in PHP, but while trying it on my Postman, it works very well.
E/flutter ( 2647): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection refused
import 'dart:convert';
import 'package:dartz/dartz.dart';
import 'package:ecommercegetx/core/class/statusrequest.dart';
import 'package:ecommercegetx/core/functions/checkinternet.dart';
import 'package:http/http.dart' as http;
class Crud {
Future<Either<StatusRequest, Map>> postData(String linkurl, Map data) async {
var check = await checkInternet();
print("###################################$check");
print("###################################1$linkurl");
print("###################################2$data");
if (await checkInternet()) {
print("checkedf");
var response = await http.post(Uri.parse(linkurl), body: data);
print("########################----33333333$response");
if (response.statusCode == 200 || response.statusCode == 201) {
Map responsebody = jsonDecode(response.body);
return Right(responsebody);
} else {
return const Left(StatusRequest.serverfailure);
}
} else {
return const Left(StatusRequest.offlinefailure);
}
}
}
Here is the repository for full code (I couldn't add more code) https://github.com/Y7gn/ecommercegetx
Try to get your IP address and insert that instead of localhost.
Write ipconfig
into your terminal and get your IP address from there. Then instead of localhost write down your IP in there.