Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如果SharedReferences键不为空,如何检查?_Flutter - Fatal编程技术网

Flutter 如果SharedReferences键不为空,如何检查?

Flutter 如果SharedReferences键不为空,如何检查?,flutter,Flutter,如何检查SharedReferences键是否为空 当我运行程序时,它会给我一个错误 1.]Future getStrings()异步{ 2.]Future\u sPrefs=SharedReferences.getInstance(); 3.]final SharedReferences prefs=等待优先权; 4.]appid=prefs.getString('appid'); 5.]打印(appid); 6.]如果(应用ID!=''){ 7.]返回appid; 8.] } 9.]返回

如何检查SharedReferences键是否为空

当我运行程序时,它会给我一个错误

1.]Future getStrings()异步{
2.]Future\u sPrefs=SharedReferences.getInstance();
3.]final SharedReferences prefs=等待优先权;
4.]appid=prefs.getString('appid');
5.]打印(appid);
6.]如果(应用ID!=''){
7.]返回appid;
8.]  }
9.]返回“”;}
上面是我的代码,只有当我运行带有
prefs.clear()的注销函数时才会显示错误

(appid!='')更改为
(appid!=null)
。Null和空字符串是不同的

您可以使用空感知运算符将其缩短为:

return appid ?? '';
return appid ?? '';