top of page

[Flutter/dart]onWillPop of willPopScope doesn't work


Overview


In flutter, if you don't want users to return to the previous page, you can wrap the widget with willPopScope and write a process that prevents users from returning at onWillPop. (See here for how to use it.)

However, even with this implementation, I can return normally. When I debug it, it seems that the method passed to onWillPop is not called in the first place.

Here describes how to deal with this case.



Cause


The cause seems to be that willPopScope was not at the root of the stack (that is, the source). In my app, I jumped from the login page to the main page with Navigator.push and put onWillPopScope there, so it seems that onWillPop was not called (reference)



Solution


In the case of a one-way transition like a login page, use pushReplacement or pushAndRemoveUntill so that the page is not left in the stack. (reference)


Navigator.of(context).pushReplacement(
    MaterialPageRoute(builder: (BuildContext context) => MyHomePage())
)

Recent Posts

See All

[Flutter/Dart] Format string with TextField

What want to do I want to create an input form using TextField. For example, if the input content is a monetary amount, I would like to display it in 3-digit delimiters with a ¥ prefix. Rather than ha

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Inquiries: Please contact us on Twitter

  • Twitter
bottom of page