Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 流量分析不';使用setState时不工作 void f(){ 字符串字符串; 设置状态(){ string=foo条件?'foo':'bar'; }); string.toUpperCase();//错误 }_Flutter_Dart_Dart Null Safety - Fatal编程技术网

Flutter 流量分析不';使用setState时不工作 void f(){ 字符串字符串; 设置状态(){ string=foo条件?'foo':'bar'; }); string.toUpperCase();//错误 }

Flutter 流量分析不';使用setState时不工作 void f(){ 字符串字符串; 设置状态(){ string=foo条件?'foo':'bar'; }); string.toUpperCase();//错误 },flutter,dart,dart-null-safety,Flutter,Dart,Dart Null Safety,如果我删除setState条件,则流分析工作!我可以将我的setState放在下面(空白setState((){}),但这只会降低代码的可读性。有没有更好的方法来做到这一点,而不必使字符串可为空并在此后检查可为空性?这就是为什么您也可以在局部范围中使用late关键字的原因 late String string; 回答你的问题: void f(){ 晚弦; 设置状态(){ string=foo条件?'foo':'bar'; }); string.toUpperCase();//有效 }

如果我删除
setState
条件,则流分析工作!我可以将我的
setState
放在下面(空白
setState((){}
),但这只会降低代码的可读性。有没有更好的方法来做到这一点,而不必使
字符串可为空并在此后检查可为空性?

这就是为什么您也可以在局部范围中使用
late
关键字的原因

late String string;
回答你的问题:

void f(){
晚弦;
设置状态(){
string=foo条件?'foo':'bar';
});
string.toUpperCase();//有效
}