Search code examples
flutterdartnavigationback

Flutter PopScope onPopInvokedWithResult not calling on pressing back button


I am using Popscope on my local authview- a screen where user enters a pin to enter the app. When user hit backbutton it is clearing the entered pin but does not close the app. It is the first screen when user opens the app. When I set canPop parameter to true it will close app without clearing entered pin. I want to clear the entered pin if user entered something and close the app when hit back button


Solution

  • You can assign false to canPop and exit the app with SystemNavigator like this:

      return PopScope(
        canPop: false,
        onPopInvokedWithResult: (didPop, result) {
          if (didPop) return;
          vm.clearPassCodeView();
          SystemNavigator.pop();
        },
        child: YourScffold(),
      );