Skip to content

Conversation

darrenaustin
Copy link
Contributor

Description

Currently any application using a WillPopCallback to veto or allow a pop to take place is required to either return true or false. However, a common use case for using the willPop mechanism in routes would be to use the return value from an AlertDialog that is asking the user whether they wanted to continue or not. When a dialog is dismissed by tapping on the background barrier the return value will from showDialog will be null which will cause the willPop mechanism to fail with an exception.

This PR relaxes the interpretation of the return value from WillPopCallback to treat null the same as false (i.e. veto the pop operation). It will only allow the pop if the callback returns true.

Related Issues

Fixes: #51768

Tests

I added a new test that checks for both null and false and ensures they are treated the same.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them?

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 13, 2020
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fluttergithubbot fluttergithubbot merged commit ff23586 into flutter:master Apr 13, 2020
@darrenaustin darrenaustin deleted the will_pop_callback branch April 13, 2020 19:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WillPopScope + alerttDialog throws an exception when tapping the background

5 participants