This error is getting while using HTTP GET method
This happens because the localhost (or 127.0.0.1) on the device is only accessible to the device itself.
You can reverse-proxy a localhost port to the Android device/emulator running adb reverse on the command prompt like so:
adb reverse tcp:5000 tcp:5000
Use the machine's IP address where the DB is running. Also, the DB should be listening to the IP 0.0.0.0 to be accessible outside the localhost.
Supposing the DB machine's IP is 192.168.1.123 it's going to be something like:
Future db() async {
print('@');
final conn = await MySQLConnection.createConnection(
host: '192.168.1.123', // <- Here
port: 3306,
userName: 'root',
password: '',
databaseName: 'flutter', // optional
);
print('^');
}
Just take care because changing the DB to listen to 0.0.0.0 is a security risk as the DB is going to be accessible to the outside world.