当没有信号时,我通过将数据存储到设备 (SQLite) 来使用离线模式。有信号后,我尝试将数据发送到 Mysql 服务器。
如何将数据从 SQLite(离线模式)发送到 MySQL 服务器?
最佳答案
在远程服务器中创建一个类似于 sqflite 数据库表的数据库。然后,使用您想要的语言创建一个 rest api(php 很容易启动)。然后,当应用程序连接到互联网时,使用 HTTP 客户端将数据发送到远程服务器。
您可以使用如下代码调用发布数据:
Future<dynamic> post(String url, {Map headers, body, encoding}) {
print(url);
print(body);
return http
.post(BASE_URL+url, body: body, headers: headers, encoding: encoding)
.then((http.Response response) {
final String res = response.body;
final int statusCode = response.statusCode;
print(res);
if (statusCode < 200 || statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
}
return _decoder.convert(res);
});
}
关于flutter - 如何使用 Flutter 将数据 SQLite(离线)发送到服务器 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54317210/