繁体   English   中英

在 Flutter 中将 SQFLite 数据库与 MySQL 同步?

[英]Sync SQFLite database with MySQL in Flutter?

我有一个反馈应用程序,我想保存一些数据以供在 Flutter 应用程序中离线使用。 我想暂时保存数据(如果互联网不可用)然后同步到 MySQL。 我在 MySQL 上有我的主数据库,在 Flutter 中我们必须使用 SQFLite 来存储离线数据。

谁能帮忙!!! 谢谢你

您可以尝试在此 SO post 中检查解决方案:

在远程服务器中创建一个类似于 sqflite db 表的数据库。 然后,使用您想要的语言创建一个 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); }); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM