-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
TextField is hidden by keyboard inside of a Modal Bottom Sheet #18564
Comments
Please add the output of |
@zoechi Done, also updated the code. TextField is visible if the bottom sheet is high enough, else it's covered, like on a screenshot |
I'm not sure if it's related, but take a look at this gist: https://gist.github.com/andrelsmoraes/9e4af0133bff8960c1feeb0ead7fd749 Behavior after fix: https://youtu.be/ESiCr0juFG8 |
Any fixes? The problem still persists. Please do Fix it because we Love #Flutter. |
@mohith7548 As of now, make sure your ModalBottomSheet is high enough (at least keyboard height + TextView height), then TextField will be visible. Else don't use MBS for your input. Also, try andrelsmoraes' solution |
Hey did you use showDialog method. When there is a text field in it. The keyboard automatically shifts the dialog up and appears on screen when the text field is tapped. Why it doesn't happen in case of ModalBottom sheet. This is a bug and it needs to be fixed soon |
@andrelsmoraes Could u provide more codes for your youtube demo? This is exactly what I want achieve. |
@jinfagang Added some comments in my gist, please check it out and tell me if you need more details. |
Please fix this. See #20638 |
This may not work for all situations, but I have a modalBottomSheet that contains only a TextField, and it was quite simple to make it move up with the keyboard: Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: TextField()
) |
None update on that yet ? |
I made a modification and the issue is fixed you can check it out here: https://gist.github.com/crimsonsuv/b25d5ebd04236f9be2aa66accba19446 |
Hi @crimsonsuv , your temporarily solution almost worked perfectly. The modal is not dismissed by clicking outside the content anymore 😢 . Edit: Just changed
to true. |
This comment has been minimized.
This comment has been minimized.
When the keyboard appears, the body of the Scaffold that contains the input focus is resized. So to ensure that the focused list item scrolls into view when the keyboard appears it made sense to put the bottom sheet in a Scaffold. Unfortunately, fixing the scaffold's height to 300 prevented it from being resized. Here's a version of the example (I've just removed the SizedBox constraint) that does work: https://gist.github.com/HansMuller/9c0c89623650d55e84ba55d78f384fad |
just add resizeToAvoidBottomPadding: true in scaffold widget |
I hope the BottomSheet can scroll to the focused TextField automatically. |
Hi, I was looking around for the solution for a while. I was use resizeToAvoidBottomInset: true, inside the Scaffold Widget. I also have my forms under the SingleChildScrollView. Here is my example code for login return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text('$title'),
),
body: SingleChildScrollView(
child: Container(
child: Column(
children: <Widget>[
login()
],
),
),
),
); |
Hi, I found the solution to be scattered. I fixed this issue where my the bottom Sheet expands towards top dynamically when input with multiple lines. I tried @andrelsmoraes gist but i couldn't edit shapes in that. Finally without using fully customised bottom_sheet.dart, Changing the value of 9.0 to 10.0 in bottom_sheet.dart , I achieved what i actually wanted. Thanks to @crimsonsuv , setting the maxHeight this way gives full screen on demand. |
Not sure about all of the repercussions yet, but this is the solution I came up with for now. https://gist.github.com/drewpayment/08e963f8cf0fa715711408a2bf33d899 |
Is this fixed now as I am stuck with it and got no solution so far. |
showModalBottomSheet(
isScrollControlled: true, // Important: Makes content maxHeight = full device height
context: context,
builder: (context) {
// Does not work
return AnimatedPadding(
padding: MediaQuery.of(context).viewInsets,
duration: const Duration(milliseconds: 100),
curve: Curves.decelerate,
child: Container(
child: Wrap(
children: [
TextField(
decoration: InputDecoration(labelText: "1"),
),
TextField(
decoration: InputDecoration(labelText: "2"),
),
TextField(
decoration: InputDecoration(labelText: "3"),
),
],
))); |
Thank you very much, this was the only solution that worked for me in case of a non-scrollable content on the bottom sheet. |
Yep worked! |
I'm going to say this issue should not be closed. I have a modal bottom sheet with a text field and there is plenty of room on the screen for it to move up but it does not. If Material spec says that no bottom sheets should have editable text then I'd be curious to know how material spec says we should handle these types of scenarios. |
@HansMuller Requesting that this gets reopened |
After combining different solutions I got this: if you don't want it to be Full screen and don't want to use the Padding workaround use showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
enableDrag: true,
isDismissible: true,
useRootNavigator: true,
builder: (BuildContext ctx) {
return Scaffold( // use CupertinoPageScaffold for iOS
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: true, // important
body: SingleChildScrollView(
child: Form(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextFormField(),
TextFormField(),
],
),
),
),
),
);
},
); on Flutter (Channel master, v1.15.3-pre.37, on Mac OS X 10.15.2 19C57, locale en-US) |
use context instead BuildContext so the code showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return SingleChildScrollView(
child:Container(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: AnyChild(),
)
);
}); |
this link works super fine try this one |
Work like a charm, you save my day. 👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏 |
Hi @andrelsmoraes , if I use the key property in the TextField a glitch happens, if possible, could you check it and fix it ? |
hi, guys, I got it fixed by increasing the height of the child widget when the keyboard gets opened.
|
With height in container it doesnt work |
none of this work for me.working on Samsung Galaxy S8 flutter sdk: ">=2.7.0 <3.0.0".there's no change ( which i though must have ) when the keyboard is opened |
@cuong292 This solution worked for me on Samsung Galaxy S7, calculating the bottom padding during runtime when keyboard is open else default padding if keyboard is not open. |
@jaganmohang it's feel like it's always padding 50 from bottom or padding equal to viewInsets.bottom.that doesnt make sense i guess.so i'm change to dialog |
default bottom padding 50 is my requirement. And since the content is inside the SingleChildScrollView there will be no issue. Anyway you already opted for a different solution so no issues. |
setting |
What if I have a textfield and a submit button with it? |
This is how I tackled it!! The AddTaskScreen class class AddTaskScreen extends StatelessWidget {
} |
Scaffold did not work for me as it caused my modal bottom sheet to top align. Instead, I used a combination of SingleChildScrollView and dynamic padding based on the viewInsets.bottom.
|
My solution is to put a child widget inside Scaffold and this worked. |
none of these suggestions worked. :( |
isScrollControlled and padding solve this problem. For everyone still having this problem, make sure you provide the correct context to showModalBottomSheet |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Result
Clicked on 4th item
Perfectly, Modal Bottom Sheet should be lifted up till a TextField is visible, just like FAB
Flutter Doctor
The text was updated successfully, but these errors were encountered: