Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Flutter Back button functionality?

Tags:

I would like to present an AdWords interstitial before the user returns to the previous page. How can I do this when the return button is pressed?

like image 876
Charles Jr Avatar asked Mar 03 '18 01:03

Charles Jr


People also ask

How do you get the back button event in Flutter?

By tapping the Android back-button (or the "pop" button) each square turns blue, one by one. Only when all squares are blue, tapping the back-button once more will return to the previous screen.

How do you handle the back button click Flutter?

How to Execute when clicking the back button In Flutter? You can override the default back arrow on the AppBarand then specify the value you would like to return to trigger the change of the state when Navigator. pop is called.

How do I add back button in Flutter app?

To add custom back button in Flutter AppBar You Just need to Use Leading in AppBar and Use IconButton for leading Just like this. To add custom back button in Flutter AppBar You Just need to Use Leading in AppBar and Use IconButton for leading Just like this.


1 Answers

I think you can make use of WillPopScope widget. You can pass a callback function which will be called when the view is about pop. Just do whatever tasks to be completed before pop and then return true.

Example:

Future<bool> _willPopCallback() async {     // await showDialog or Show add banners or whatever     // then     return true; // return true if the route to be popped }   //then pass the callback to WillPopScope new WillPopScope(child: new Scaffold(), onWillPop: _willPopCallback) 

Hope that helps!

like image 189
Hemanth Raj Avatar answered Sep 24 '22 10:09

Hemanth Raj