Search code examples
flutterflutter-webflutter-go-router

WillPopScope not working with go_router web Flutter


WillPopScope(
 onWillPop: () async {
 log('WillPopScope: working in call');
  return new Future(() => true);
 }
 child: Scaffold()
)

I am using go_router for navigating through pages in Web. Here onWillPop seems to be never called. How can we listen when back button pressed on WEB.


Solution

  • You can use onExit

              GoRoute(
              path: 'new',
              onExit: (context) {
                //
                // Some OnExit Logic like OnWillPop
                // 
                return true;
              },
              builder: (BuildContext context, GoRouterState state) {
                //
                // Some OnEnter Logic 
                // 
                return NewScreen();
              }),