使用颤振共享偏好以节省颜色 [英] Sharedpreferencs with flutter to save color

查看:9
本文介绍了使用颤振共享偏好以节省颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望容器具有某种颜色,它来自 sharedpreference 或类似的东西!有没有解决这个问题的小工具!!或者我可以通过共享偏好来做到这一点!如果我能!如何?

I want a container to be of a color, that comes from sharedpreference or something like that! Is there a widget to solve this!! Or can I just do this with sharedpreference!! If I can! How?

推荐答案

更好的方法是保存color.value.

使用

final prefs = await SharedPreferences.getInstance();
Color myColor = Color(prefs.getInt('color') ?? Colors.blue.value);
// change Colors.blue to a default color

获取颜色,并且

prefs.setInt('color', myColor.value);

保存颜色.

这篇关于使用颤振共享偏好以节省颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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