Issue
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(),
);
}
}
There’s an Invalid constant value error in body: pages[0]
if I call the Widget directly like body: MessagesPage()
then there’s no error.
I tried making everything const but nothing’s helping.
Is there any update in the new version of Flutter or have I done some mistake?
Solution
remove const
keyword:
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(),
);
}
}
Answered By - Ravindra S. Patil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.