【问题标题】:Sync SQFLite database with MySQL in Flutter?在 Flutter 中将 SQFLite 数据库与 MySQL 同步?
【发布时间】:2019-09-20 10:19:29
【问题描述】:

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

谁能帮忙!!! 谢谢你

【问题讨论】:

  • flutter app adhara_socketio flutter 包 node.js socket.io mysql
  • 既然socket.io知道socket连接是否在线,那么你就可以同步你的数据了
  • 谢谢 @KennethLi 我会搜索这个。

标签: mysql database flutter synchronization sqflite


【解决方案1】:

您可以尝试在this 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);
});
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 2019-01-30
    • 2021-10-12
    • 2017-01-06
    • 2016-11-28
    • 2013-11-12
    • 1970-01-01
    • 2019-12-03
    相关资源
    最近更新 更多