This is my source code. I have internet permission in android manifest. I have also tried ip address instead of localhost. All my database and password is correct. I don't know how to detect this error.
class _MyHomePageState extends State<MyHomePage> {
Future db() async {
List name = [];
List id = [];
String url = "https://retoolapi.dev/GUILOx/data";
final response = await http.get(Uri.parse(url));
var responseData = json.decode(response.body);
for (var singleUser in responseData) {
id.add(singleUser["id"]);
name.add(singleUser["name"]);
}
final conn = await MySQLConnection.createConnection(
host: "localhost",
port: 3306,
userName: "root",
password: "kl32K4893*",
databaseName: "flutter",
);
await conn.connect();
await conn.execute("CREATE TABLE users (id int , name varchar(255));");
var len = id.length;
for (var i = 0; i < len; i++) {
await conn.execute(
"INSERT INTO users (id, name) VALUES('${id[i]}', '${name[i]}');");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: (){db();},
backgroundColor: Colors.red,
child: const Icon(Icons.add)
),
);
}
}