我是 flutter 的新手,我試圖測驗一些庫。但不幸的是,當我運行此代碼時,出現錯誤:
錯誤資訊:
error G4A9793AD: The value 'null' can't be assigned to the parameter type 'Key' because 'Key' is not nullable.
錯誤圖片網址
...some code...
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MainPage(title: 'Flutter Convex BottomBar Sample'),
);
}
}
class MainPage extends StatefulWidget {
MainPage({required Key key, required this.title}) : super(key: key);
...some code...
uj5u.com熱心網友回復:
或者洗掉Key key從變數MainPage通過洗掉它,
或者只提供一個密鑰
home: MainPage(title: 'Flutter Convex BottomBar Sample',key : Key('homepage'),),
uj5u.com熱心網友回復:
您不能將值傳遞null給key引數,因為它是不可為空的(不能具有null作為值)以將其標記為可空,您應該添加?:
MainPage({required Key? key, required this.title}) : super(key: key);
無論如何,我認為這不是你想要的,因為它也是不允許的。只需洗掉required關鍵字或向其傳遞有效密鑰:
MainPage({Key key, required this.title}) : super(key: key);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/337350.html
上一篇:如何建立緩沖區溢位有效負載
