skip to Main Content

I am working on a flutter application, where I made my custom loading bar, so whenever I set the value of loading bar *true, it shown up. But the main problem is, when I hit the back button, It goes back and loading bar get closed. I want it to never close. And again, I am not talking about showDialog function. Please help me flutter developers. Thank you.

2

Answers


  1. You probably need to use the widget WillPopScope: it prevents the user from closing/going back unless the condition specified in the onWillPop argument is true. Just set onWillPop to always return false , and you should be good to go.

    See here.

    Login or Signup to reply.
  2. Yes, we’re talking about WillPopScope. This will catch event your press back button in Android or swipe back in iOS. All you need is just wrap your Scaffold inside WillPopScope:

    WillPopScope(
          onWillPop: () async {
            // do something...
          },
          child: Scaffold()
    )
    

    References:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search