Search code examples
flutternavigatormaterialpageroute

Navigation on flutter on debug in Visual Studio Code


I'm building an application in flutter, I build two pages the main page and a configuration page, after that I added two buttons to the main page, one of then to navigate to the configuration page with this code:

void _gotoConfigurationPage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return const ConfigurationPage(title: 'ConfigurationPage');
    }));
  }

But when I try to debug the application in an Android emulator or an Android phone, the navigation doesn't work, and the other buttons stop working, BUT when I open the application in the emulator or on the phone, the navigation works!

Am I doing something wrong?

===EDIT===

This is the code of the button in the main page used to navitate to the configuration page.

floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          FloatingActionButton(
            onPressed: _gotoConfigurationPage,
            tooltip: 'Configuration',
            child: const Icon(Icons.settings),
          ),
          FloatingActionButton(
            onPressed: _action2,
            tooltip: 'Action2',
            child: const Icon(Icons.settings),
          ),
        ],
      ),

Solution

  • After some additional tests I realized some things, the first one was that the debugger get paused when I try to navigate and if I clicked in continue the application reach the configuration page, the second one was a message on console

    W/OnBackInvokedCallback( 6052): OnBackInvokedCallback is not enabled for the application.
    W/OnBackInvokedCallback( 6052): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
    

    after adding that on the manifest file in the console starts to appear another message

    Exception caught by scheduler library 
    
    There are multiple heroes that share the same tag within a subtree.
    

    with that in mind I found There are multiple heroes that share the same tag within a subtree, so I modified the buttons code and now the navigation works properly.