2

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 Answers2

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.

il_boga
  • 1,305
  • 1
  • 13
  • 21
1

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:

Nguyen family
  • 749
  • 2
  • 12