Navigator.push is not working in Flutter?

I’m making a learning app that has 2 buttons

1: Lead you directly learning dashboard

2: The login & signup

The start learning button work fine,
the problem with the login button

When I clicked nothing
happed
there are no errors in my code, but the button is not working, and I don’t know why

The code for login button:

//------------------------------------------------------------------------------
// Start Learning Button..
//------------------------------------------------------------------------------
 Container(
                  padding: const EdgeInsets.all(18),
                  margin: const EdgeInsets.all(20),
                  width: double.infinity,
                  decoration: BoxDecoration(
                    gradient: const LinearGradient(colors: [
                      Color.fromARGB(255, 240, 142, 14),
                      Color.fromARGB(255, 250, 185, 88),
                    ], begin: Alignment.centerLeft, end: Alignment.centerRight),
                    boxShadow: [
                      BoxShadow(
                        color: AppColor.accentColor.withOpacity(0.3),
                        spreadRadius: 4,
                        blurRadius: 8,
                        offset: const Offset(0, 0),
                      ),
                    ],
                    borderRadius: BorderRadius.circular(12),
                  ),
//------------------------------------------------
// boutton input
                  child: GestureDetector(
                    child: Text(
                      'Start Learning',
                      style: AppFont.bigText,
                      textAlign: TextAlign.center,
                    ),
                    onTap: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => const selectLanguagScreen()),
                      );
                    },
                  ),
                ),
//------------------------------------------------------------------------------
// Login - signup
//--------------------------------------------------------------------------------
                TextButton(
                  onPressed: () {
                    print('hello');
                    MaterialPageRoute(
                        builder: (context) => const loginScreen());
                  },
                  child: Text(
                    'login-Sing up',
                    style: AppFont.bigText.copyWith(
                        color: Colors.orange,
                        decoration: TextDecoration.underline),
                  ),
                ),

This is how it looks:

image

This what the DEBUG CONSOLE shows
image

Appreciate if someone can advise. Thank you in advance!

>Solution :

You need to use Navigator.of(context).push to go new route

Navigator.of(context).push(
          MaterialPageRoute(builder: (context) => const loginScreen()));

More about navigation

Leave a Reply