如何修復此錯誤。

我的代碼
_患者檔案,患者檔案:[],患者處方:空,);//空錯誤
uj5u.com熱心網友回復:
使 patientPrescription 成為可為空的變數。以下是如何在 dart 中創建一個可為空的變數 - “在資料型別后加上問號”。例如,讓我們創建一個名為“apple”的字串變數,如下所示 -
main(){
String apple="hello";
apple=null;
print(apple);
}
現在,dart 會報錯。但是,如果我用 String? 替換 String?,錯誤就會消失。
main(){
String? apple="hello";
apple=null;
print(apple);
}
同理,int可以換成int?,double可以換成double? 我希望這會有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/449684.html
上一篇:Flutter推送新路由時使用`pushReplacementNamed`和`pushReplacement`有什么區別?
