Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading