New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[showModalBottomSheet] fix: showModalBottomSheet does not move along keyboard #71636
[showModalBottomSheet] fix: showModalBottomSheet does not move along keyboard #71636
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Kindly review my pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks solid. Please add a unit test to make sure someone doesn't accidentally revert it (probably a golden test).
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
I'm writing a test for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny issues. Everything else looks great!
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Suggested changes done. |
Updating Forked Repository
@dkwingsmt Updated my branch to the latest master. That should resolve some failing tests. |
? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@dkwingsmt Could we have a way to make this change opt out? I currently have some modal bottom sheets where I place the textfields (usually for filtering results) at the top of a quite large bottomSheet, so the keyboard will not hide it. With this PR everything will be pushed above the keyboard which may be considered somewhat breaking. What are your thoughts? |
@davidmartos96 You are right. Although to make a modal bottom sheet hidden by the on-screen keyboard does not really sound correct to me. A displayed modal bottom sheet is supposed to prevent the user from interacting with the rest of the app. Will normal |
@dkwingsmt I may have not expressed myself correctly. Sorry about that. |
Can you achieve the same result by manually applying a negative bottom padding? Actually, you can get the height of your sheet and the screen height to calculate the exact amount of underflow for you to avoid overflowing. |
@dkwingsmt I'm not sure I follow you with the negative padding. Does Flutter support negative padding? |
Personally, I think this is a bad idea to force ModalBottomSheet to resize itself. I am experiencing the same issue as @davidmartos96 says. At least we need a parameter to control if the ModalBottomSheet should resize or not (just like Scaffold). And why padding should wrap BottomSheet to force resize to avoid keyboard? (we can just add padding inside ModalBottomSheet to achieve the same effect.) |
@HansMuller Are you more familiar with how Material Design defines ModelBottomSheet? Can you take a look at the requests above? |
@dkwingsmt Thanks for your quick response! Please imagine ModalBottomSheet takes 5/6 of full-screen height and it used to pick a country(e.g. New Zealand), so it will be a scrollable list and contains many items, and on the top of this list, there is a search bar that contains a TextField. If the ModalBottonSheet forcibly resizes as the keyboard shows, It will push the search bar to the very top of the screen, it not only breaks the UI looking but also break the feature. Because the phone notification bar will overlay on it. Moreover, padding when the keyboard shows is a brutal way to avoid keyboard overlay. Please check out this https://pub.dev/packages/keyboard_avoider package. I don't think flutter should limit us on how to design the Application. |
…e along keyboard (flutter#71636)" This reverts commit 45cf279.
We're reverting this PR in #77286. Various sources have reported that the previous behavior is the desired one. |
Any tips on what to do to have the behavior of the original commit (moving up with the keyboard)? Maybe an specific modal could be created, like showModalBottomSheetFlexible ? I'd prefer to have it behave that way |
Actually it you be much better if one could simply define the "height" of it. Being able to elongate it up just a little would solve my problem. And also being able to define which children would move upwards with the keyboard, and which would get hidden behind the keyboard. That would be ideal. |
@totroi You can get the behavior by wrapping the bottom sheet builder with: Padding(
padding: MediaQuery.of(context).viewInsets
) That's essentially what the reverted PR was doing |
Thanks! Problem is I'm seeking to move a Card inside the modal up, and move the modal up just the amount required for the Card to move. Like about 30 pixels... I managed to shrink all the paddings inside the Card widget and it looks okay, but the best result would be those 30 pixels up whenever the keyboard is opened. |
Description
This issue was found in release 1.22, 1.23, 1.24 that the
showModelBottomSheet
was not moving along the keyboard, the bottom sheet contains aTextField
which open up the keyboard on focus, so if the height of bottom sheet is less then the height of keyboard then the bottom sheet was hidden behind the keyboard.showModelBottomSheet with
TextField
unfocused:When we Focus on
TextField
- Before Changes:Bottom Sheet is hidden behind the keyboard.
When we Focus on
TextField
- After Changes:Related Issues
#71418
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.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read [Handling breaking changes].