[英](Android Studio, Flutter) Connection timed out when trying to run my app using real device
I am running my app using real android device and in my flutter I used mysql1 to connect to localhost database.我正在使用真实的 android 设备运行我的应用程序,在我的 flutter 中,我使用 mysql1 连接到本地主机数据库。 There is no problem when running the app on emulator but when comes to real device there is always a connection error.在模拟器上运行应用程序没有问题,但在真机上总是出现连接错误。 Below is my mysql.dart file:下面是我的 mysql.dart 文件:
/*This is a database configuration file*/
import 'package:mysql1/mysql1.dart';
class Mysql {
static String host = '10.0.2.2',
user = 'root', //User
db = 'users'; //Database name
static int port = 3306; //MySQL port number
Mysql();
Future<MySqlConnection> getConnection() async {
var settings = new ConnectionSettings(
host: host,
port: port,
user: user,
db: db);
return await MySqlConnection.connect(settings);
}
}
I have tried a to change the host to my localhost ip and still getting the same error.我尝试将主机更改为我的本地主机 ip,但仍然出现相同的错误。 Has anyone run into the same problem?有没有人遇到同样的问题?
Instead of using mysql1,You should have to use sqflite in flutter https://pub.dev/packages/sqflite .而不是使用 mysql1,您应该必须在 flutter https://pub.dev/packages/sqflite 中使用 sqflite 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.