Flutter Web的Shared_Preferences? [英] Shared_Preferences for Flutter Web?

查看:101
本文介绍了Flutter Web的Shared_Preferences?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Shared_preferences( https://pub.dev/packages/shared_preferences )似乎不起作用用于Flutter for Web.

Shared_preferences (https://pub.dev/packages/shared_preferences) doesn't seem to work for Flutter for Web.

按下按钮时会调用以下功能.

I have the following function that's called when a button is pressed.

 getEmail() async {
    print("reached 1st line");
    SharedPreferences prefs = await SharedPreferences.getInstance();
    print("reached 2nd line");
    String _confirmedEmail = prefs.getString('_confirmedEmail') ?? "";
)

它显示到达第一行",但不显示到达第二行",这意味着程序不会经过await语句.有趣的是,我也没有任何错误.似乎只是忽略了await语句之后的其余功能.

It prints "reached 1st line" but not "reached 2nd line", which means the program doesn't go past the await statement. Interestingly I don't get any error either. It seems to just ignore the rest of the function after the await statement.

在Flutter for Web中存储共享首选项的最佳选择是什么?

What is the best alternative to store shared preferences in Flutter for Web?

推荐答案

好消息,版本0.5.6 shared_prefs 默认情况下flutter支持网络

Great news, from version 0.5.6 shared_prefs flutter supports web by default

现在它包括网络的共享首选项

您的代码应该可以正常工作,而无需更改,只需更新 pubspec.yaml

Your code should work without changes, just update dependency in pubspec.yaml

dependencies:
 shared_preferences: ^0.5.6

这篇关于Flutter Web的Shared_Preferences?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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