[英]How can I send data SQLite (offline) to server MySQL using Flutter?
When there is no signal I use offline mode by storing data to the device (SQLite).当没有信号时,我通过将数据存储到设备 (SQLite) 来使用离线模式。 After there is a signal I try to send the data to the Mysql server.有信号后,我尝试将数据发送到 Mysql 服务器。
How can I send data from SQLite (offline mode) to MySQL server?如何将数据从 SQLite(离线模式)发送到 MySQL 服务器?
create a DB similar to your sqflite db's table in a remote server.在远程服务器中创建一个类似于 sqflite db 表的数据库。 then, create a rest api using your desired language(php is easy to start).然后,使用您想要的语言创建一个 rest api(php 很容易上手)。 then, when the app is connected to internet, use HTTP client to send the data to the remote server.然后,当应用程序连接到互联网时,使用 HTTP 客户端将数据发送到远程服务器。
you can use a code like below for the post data call:您可以使用如下代码进行后期数据调用:
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);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.