skip to Main Content
    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?

2

Answers


  1. remove const

      @override
      Widget build(BuildContext context) {
        return Scaffold( // here need to change
          body: pages[0],
          bottomNavigationBar: _BottomNavigationBar(),
        );
      }
    
    Login or Signup to reply.
  2. 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(),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search