Could not find a generator for route RouteSettings("/GeneralAnnouncements", null) in the _WidgetsAppState

Viewed 80

When i run this and press on the button it gets the error (Could not find a generator for route RouteSettings("/GeneralAnnouncements", null) in the _WidgetsAppState. So can I know what is the problem here? As i want to use only named routes so please don't recommend for me to use .push as it doesn't suit me. The problem is in this Navigator.pushNamed(context, '/GeneralAnnouncements'); line but I don't know why?

This is my code:

class home extends StatelessWidget {
  const home({key}) : super(key: key);
  static const routeName = '/home';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Color(0xFF6D0131),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            CircleAvatar(
                radius: (100),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(110),
                  child: Image.asset('images/logo.png'),
                )),
            SizedBox(
              height: 10.0,
            ),
            GestureDetector(
              onTap: () {
                Navigator.pushNamed(context, '/GeneralAnnouncements');
              },
              child: Padding(
                padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
                child: Container(
                  height: 100.0,
                  decoration: BoxDecoration(
                    color: Color(0xFF8D0235),
                    borderRadius: BorderRadius.circular(20.0),
                  ),
                  margin: EdgeInsets.only(bottom: 10.0),
                  padding: EdgeInsets.only(left: 18.0),
                  child: Center(
                    child: Text(
                      '        General \nAnnouncements',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 35.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),
              ),
            ),
            
          ],
        ),
      ),
    );
  }
}

This is the MaterialApp:

runApp(MaterialApp(
    initialRoute: '/homepage',
    routes: {
      "/homepage": (context) => MyHomepage(),
      '/login': (context) => LoginScreen(),
      '/registration': (context) => RegistrationScreen(),
      "/GeneralAnnouncements": (context) => GeneralAnnouncements(),
      '/MyCalendar': (context) => MyCalendar(),
      "/home": (context) => home(),
    },
  ));
0 Answers
Related