Flutter keyboard makes textField hidden - flutter

I have a problem, when the textfield is tapped, the flutter keyboard opens up and it cover almost the whole the screen, including the TextField.
I've tried all the solutions I've seen online:
Wrapping the widget in a SingleScrollView
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
Set Scaffold to not resizeonBottom
Still, the keyboard is hiding the textField.
This is what I did:
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
[....................]
Padding(
padding: const EdgeInsets.all(8.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height/2),
child: TextField(
style: TextStyle(
color: TheBaseColors.lightRed,
fontWeight: FontWeight.bold,
fontFamily: 'FoundersGrotesqueXCond',
),
onTap: () {},
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: 'OCCUPATION',
hintStyle: TextStyle(fontSize: 20.0, color: Colors.blueGrey),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
),
),
),
),
],
),
);
}
}

Try wrap your single child in an scaffold and set the property resizeToAvoidBottomInset to true. So when you tap something in this page, the keyboard will push your page up to not cover your page.

Scaffold(
resizeToAvoidBottomInset: false,
child: ....
)
Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(13.0),
child: Row(
children: [
Expanded(
child: TextFormField(
controller: _msgController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
contentPadding: new EdgeInsets.symmetric(
vertical: 15.0, horizontal: 15.0),
border: OutlineInputBorder(
// width: 0.0 produces a thin "hairline" border
borderRadius: BorderRadius.all(Radius.circular(60.0)),
borderSide: BorderSide.none,
//borderSide: const BorderSide(),
),
hintStyle:
TextStyle(color: Colors.black, fontSize: 14.0),
filled: true,
fillColor: Colors.grey[300],
hintText: 'write here...'),
),
),
)
Add this

Related

Allow widget to be pushed off the screen by content below when the keyboard is opened

What I'm trying to do is have an image widget at the top of the screen then have some inputs and a button at the bottom for logging in like so:
And then when the user opens the keyboard I want the inputs to stick to the bottom of screen being pushed up by the keyboard which is pretty easy to do on a large device but on smaller devices the inputs hit the image and get covered by the keyboard causing errors so instead I want to have the image simply pushed upwards and off the screen by the inputs but I can't figure out how to do it so far I've managed to get this:
Which is obviously not quite what I'm after as I don't want the image to shrink I just want it to be pushed off the screen any suggestions would be much appreciated
Minimal code to get the results shown in the images
return Stack(
children: [
Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(child: Image.asset('assets/temp.png', height: 115)),
),
Padding(
padding: EdgeInsets.fromLTRB(
50, 0, 50, isKeyboardVisible ? 10 : 50),
child: Column(
children: [
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Username',
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Password',
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
Center(
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(20),
color: Colors.lightGreen,
child: MaterialButton(
onPressed: () {},
child: Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
),
),
],
),
),
],
),
),
],
);
EDIT: So I've been playing around for a little while and I've managed to get further but now all the way this is the code I have now:
return Stack(
children: [
Scaffold(
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height -
MediaQuery.of(context).viewInsets.bottom, // screen height minus keyboard height but interestingly if i just do MediaQuery.of(context).size.height i dont get errors so its almost working
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Center(
child: Image.asset('assets/temp.png', height: 115),
),
Padding(
padding: EdgeInsets.fromLTRB(
50, 0, 50, isKeyboardVisible ? 10 : 50),
child: Column(
children: [
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Username',
contentPadding: EdgeInsets.fromLTRB(
20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Password',
contentPadding: EdgeInsets.fromLTRB(
20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
Center(
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(20),
color: Colors.lightGreen,
child: MaterialButton(
onPressed: () {},
child: Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
),
),
],
),
),
],
),
),
),
),
],
);
As you can see in the comment thats in the code I'm taking the screen height then taking the keyboard height away as it then shrinks the Columns pushing the inputs up but I get errors however if I don't take the keyboard height away it almost works but there is a massive gap between the image and the inputs which is not what I want hence why I'm removing the keyboard height but then that causes issues so I can't figure out what I'm supposed to do to get the desired result.
remove Flexible and then
try wrapping your column with SingleChildScrollView
Scaffold(
body: SingleChildScrollView(child:Column(

how enable TextFormField input flutter

I'm starter in Flutter and Dart .I created TextFormField input , I would like to make it enable but i can't do that .As you see i tried to use some solutions but they couldn't help me , it's always disable . Ho i can fix it ? Any help please ?
My code :
body: Directionality(
textDirection: TextDirection.ltr,
child: Stack(
children: <Widget>[
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
Positioned(
bottom: 0,
child: Container(
height: 60,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border(top: BorderSide(color: Colors.grey))),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.camera_enhance,
color: Colors.grey,
),
onPressed: () {}),
Container(
padding: EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
width: MediaQuery.of(context).size.width - 50,
child: TextFormField(
// enabled: true,
// readOnly: false,
// enableInteractiveSelection: true,
controller: _addcomment,
decoration: InputDecoration(
hintText: 'Type something',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: addComment,
),
contentPadding: EdgeInsets.all(5),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
)),
],
),
)
],
),
)),
and this TextFormField Input
Here is Your Correct Code :
body: Directionality(
textDirection: TextDirection.ltr,
child: Stack(
children: <Widget>[
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
Positioned(
bottom: 0,
child: Container(
height: 60,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border(top: BorderSide(color: Colors.grey))),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.camera_enhance,
color: Colors.grey,
),
onPressed: () {}),
Container(
padding: EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
width: MediaQuery.of(context).size.width - 50,
child: TextFormField(
autoFocus: true,
controller: _addcomment,
decoration: InputDecoration(
hintText: 'Type something',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: addComment,
),
contentPadding: EdgeInsets.all(5),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
)),
],
),
)
],
),
)),
add property autoFocus and set it's value as a true.

Flutter textformfield

How can I have a new line property in the textfield widget? SO that the text entered when reaches a certain point, it shifts to a new line. Can anyone help me fix this?
Code :
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2,
),
borderRadius: BorderRadius.circular(10)),
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: TextFormField(
decoration: InputDecoration(
hintText: 'UserName',
hintStyle:
TextStyle(fontWeight: FontWeight.w400, fontSize: 24.0)),
),
),
),
)
Output:
From the Official Docs, The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line
text field. maxLines must not be zero.
You just have to add maxLines: null
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2,
),
borderRadius: BorderRadius.circular(10)),
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: TextFormField(
maxLines: null,
decoration: InputDecoration(
hintText: 'UserName',
hintStyle:
TextStyle(fontWeight: FontWeight.w400, fontSize: 24.0)),
),
),
),
)

How to hide the things behind the textfield border?

I am trying to make a textfield with rounded border and some drop shadow,
when i use elevation it shows some parts outside the border, please have alook in the image i had attached.
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 30.0,
child: Material(
elevation: 2.0,
shadowColor: Colors.grey,
child: TextField(
autofocus: false,
style: TextStyle(
color: Colors.black,
),
decoration: kTextFieldDecorationCircular,
onChanged: (value){
searchWord = value;
},
onEditingComplete: searchTheWord,
),
),
),
),
);
const kTextFieldDecorationCircular = InputDecoration(
contentPadding: EdgeInsets.all(2.0),
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(Icons.search, color: Colors.grey,),
hintText: 'Search',
hintStyle: TextStyle(color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
);
This is my code.
Thank you in advance.
You could add this to your Material widget:
borderRadius: BorderRadius.all(Radius.circular(50.0)),

How to push up TextFormField to enable user input flutter

I have this TextFormFields in a scrollView. The top 2 TextFormFields allow the user to see what they are typing. However, on clicking the third TextFormField, the keyboard appears above the TextFormField and hides it so the user does not see what they are typing. How can I correct this.
On clicking the first one.
.
Clicking the Third One, it is hidden partially
Clicking the fourth, nothing can be seen at all. Keyboard obscures it
The Code I have
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Container(
height: 200.0,
width: double.infinity,
color: Colors.black,
),
Expanded(
child: SingleChildScrollView(
child: Form(
child: Column(children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: Theme.of(context).textTheme.subhead,
labelText: 'One',
contentPadding: EdgeInsets.all(15.0),
isDense: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: Theme.of(context).textTheme.subhead,
labelText: 'Two',
contentPadding: EdgeInsets.all(15.0),
isDense: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: Theme.of(context).textTheme.subhead,
labelText: 'Three',
contentPadding: EdgeInsets.all(15.0),
isDense: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
),
),
The normal default android keyboard used