到目前为止,每当我需要在Widget中使用条件语句时,我已经完成了以下操作(使用Center和Containers作为简化的虚拟示例):
new Center(
child: condition == true ? new Container() : new Container()
)
Run Code Online (Sandbox Code Playgroud)
虽然当我尝试使用if/else语句时,它会导致死代码警告:
new Center(
child:
if(condition == true){
new Container();
}else{
new Container();
}
)
Run Code Online (Sandbox Code Playgroud)
有趣的是,我尝试使用switch case语句,它给了我相同的警告,因此我无法运行代码.我做错了什么或者是不是因为有死代码而无法使用if/else或switch语句而没有颤抖?