sqflite 或 Shared Preference,哪个适合在flutter本地存储用户数据? [英] Sqflite or Shared Preference, which is suitable for storing user data locally in flutter?

查看:85
本文介绍了sqflite 或 Shared Preference,哪个适合在flutter本地存储用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个应用程序,该应用程序将允许用户使用一些基本信息(如姓名、名称等)离线创建帐户.我希望用户能够完全离线使用该应用程序.但我也想保留一个选项来创建一个带有一些身份验证方法的帐户,例如社交登录、电子邮件、电话.用户可以在本地创建帐户后从他们的设置中执行此操作.一旦他们创建/连接帐户,我想将本地可用的数据备份到 Firebase 数据库.

So I am working on an app that will allow the users to create an account offline with some basic information such as name, designation etc. And I want the user to be able to use the app completely in offline. But also I want to keep an option to create an account with some authentication methods such social login, email, phone. Users can do this from their settings after they have created the account locally. And Once they create/connect the account I want to backup the data that is available locally to firebase database.

但我很困惑哪种方法最适合于此.我应该为此使用 Sqflit 还是 Shared Preference 包.

But I am confused which would be the most suitable approach for this. Should I use Sqflit or Shared Preference package for this.

提前感谢您的帮助.

推荐答案

Sharedpreferences 用于存储简单的键值对,而 Sqlite 旨在在 SQL 数据库中存储大量类似的数据.

Sharedpreferences is used to store simple key-value pairs while Sqlite is designed to store lots of similar data in a SQL database.

它有一些限制:

  1. 它不是为存储大量数据而设计的
  2. '不能保证写入返回后会持久化到磁盘,因此该插件不得用于存储关键数据.'(来自包装说明)

就您而言,身份验证数据至关重要,因此我不建议使用 SharedPreferences.

In your case, authentication data is critical and therefore I would not recommend using SharedPreferences.

如果您想了解有关该主题的更多信息,请查看 Flutter Cookbook 用于持久化数据.

If you want more information about the topic, have a look at the Flutter Cookbook for persisting data.

这篇关于sqflite 或 Shared Preference,哪个适合在flutter本地存储用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆