Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpUtil.getBool('key', defValue: true) 判断好像有误 #20

Closed
chenyanbin-dkhs opened this issue Oct 8, 2019 · 2 comments
Closed

SpUtil.getBool('key', defValue: true) 判断好像有误 #20

chenyanbin-dkhs opened this issue Oct 8, 2019 · 2 comments

Comments

@chenyanbin-dkhs
Copy link

if (SpUtil.getBool('key_test', defValue: true)) {
       SpUtil.putBool('key_test', false); //虽然设置成false ,但是下次还会执行进来
  }

看了下源码

 static bool getBool(String key, {bool defValue = false}) {
    if (_prefs == null) return defValue; 
    return _prefs.getBool(key) ?? defValue;  
  }

可能需要做以下修改

 static bool getBool(String key, {bool defValue = false}) {
    if (_prefs == null || _prefs.getBool(key) == null) return defValue; 
    return _prefs.getBool(key);
  }
@Sky24n
Copy link
Owner

Sky24n commented Oct 8, 2019

A ?? B, ??的意思就是,前面A为null就使用B的值

@chenyanbin-dkhs
Copy link
Author

你是对的,好像每次hot reload后,值就会被清空了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants