使用带有共享首选项的字符串数据

发布于 2025-02-13 00:25:39 字数 65 浏览 1 评论 0原文

我有一个登录页面,我想保存具有共享首选项的用户名数据,并在我的应用中使用它。我该怎么做?我不知道如何使用共享首选项。

I have a login page and I want to save my username data with shared preferences and use it in my app. How can I do that? I couldn't figure out how to use the shared preferences.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2025-02-20 00:25:39

似乎您还没有诚实地尝试。来自文档它是在顶部写的:

// Obtain shared preferences.
final prefs = await SharedPreferences.getInstance();

// Save an String value to 'action' key.
await prefs.setString('action', 'Start');

// Try reading data from the 'action' key. If it doesn't exist, returns null.
final String? action = prefs.getString('action');

It seems like you haven't given in an honest try yet. From the documentation it is written at the top:

// Obtain shared preferences.
final prefs = await SharedPreferences.getInstance();

// Save an String value to 'action' key.
await prefs.setString('action', 'Start');

// Try reading data from the 'action' key. If it doesn't exist, returns null.
final String? action = prefs.getString('action');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文