class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
final List pages = const [
MessagesPage(),
NotificationsPage(),
CallsPage(),
ContactsPage(),
];
@override
Widget build(BuildContext context) {
return const Scaffold(
body: pages[0],
bottomNavigationBar: _BottomNavigationBar(),
);
}
}
body: pages[0]如果我直接呼叫小部件,則會出現 Invalid constant value 錯誤,就像body: MessagesPage()沒有錯誤一樣。我嘗試將所有內容都設定為常量,但沒有任何幫助。
新版本的 Flutter 有沒有更新或者我做錯了什么?
uj5u.com熱心網友回復:
洗掉const關鍵字:
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
final List pages = const [
MessagesPage(),
NotificationsPage(),
CallsPage(),
ContactsPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(//remove const keyword here
body: pages[0],
bottomNavigationBar: _BottomNavigationBar(),
);
}
}
uj5u.com熱心網友回復:
消除 const
@override
Widget build(BuildContext context) {
return Scaffold( // here need to change
body: pages[0],
bottomNavigationBar: _BottomNavigationBar(),
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/382583.html
下一篇:Flutter字體真棒圖示未顯示
