I was add 2 input field in the same row in the mobile screen input fields are collapsed when showing error.
Row(
children: <Widget>[
Expanded(
flex: 2,
child: TextFormField(
autovalidateMode: AutovalidateMode
.onUserInteraction,
keyboardType: TextInputType.number,
controller: controller.plz,
validator: ValidationBuilder(
localeName: localeLanguage)
.digits()
.minLength(5)
.required()
.build(),
decoration: inputdecoration(),
)),
SizedBox(width: 10.0),
Expanded(
flex: 3,
child: TextFormField(
autovalidateMode: AutovalidateMode
.onUserInteraction,
validator: ValidationBuilder(
localeName: localeLanguage)
.required()
.build(),
controller: controller.place,
decoration: inputdecoration(),
))
],
),
InputDecoration(
errorMaxLines: 3,
helperText: '',
contentPadding:
new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
fillColor: AsianmastaColors.white,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0)))
//after showing error
new
Its hard to read the code. First update your question adding the code on code block. You will find {} symbol just above the text pad.
give the Row crossAxisAlignment.start and it will work
Row(
crossAxisAlignment: CrossAxisAlignment.start
children: <Widget>[
Expanded(
flex: 2,
child: TextFormField(
autovalidateMode: AutovalidateMode
.onUserInteraction,
keyboardType: TextInputType.number,
controller: controller.plz,
validator: ValidationBuilder(
localeName: localeLanguage)
.digits()
.minLength(5)
.required()
.build(),
decoration: inputdecoration(),
)),
SizedBox(width: 10.0),
Expanded(
flex: 3,
child: TextFormField(
autovalidateMode: AutovalidateMode
.onUserInteraction,
validator: ValidationBuilder(
localeName: localeLanguage)
.required()
.build(),
controller: controller.place,
decoration: inputdecoration(),
))
],
),
Related
I want the blue lines not to disappear when it scrolls up.
The blue lines are related to OutlineInputBorder. But it stays inside of SingleChildScrollView widget. How can I do it?
related codes
Expanded(
child: Container(
constraints: BoxConstraints(maxHeight: 100),
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.circular(20.0))),
child: SingleChildScrollView(
child: TextField(
controller: _textEditingController,
keyboardType: TextInputType.multiline,
maxLines: null,
autocorrect: true,
enableInteractiveSelection: true,
enableSuggestions: true,
textCapitalization:
TextCapitalization.sentences,
decoration: InputDecoration(
hintText: "Bir not ekleyin",
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
),
),
),
),
),
),
I solved the problem by putting container inside container. But I removed the OutlineInputBorder.
If you have a better solution, please let me know.
new codes
Expanded(
child: Container(
constraints: BoxConstraints(maxHeight: 100),
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius:
BorderRadius.all(Radius.circular(20.0))),
child: Container(
margin: EdgeInsets.all(2.0),
padding: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.circular(18.0))),
child: SingleChildScrollView(
child: TextField(
controller: _textEditingController,
keyboardType: TextInputType.multiline,
maxLines: null,
autocorrect: true,
enableInteractiveSelection: true,
enableSuggestions: true,
textCapitalization:
TextCapitalization.sentences,
decoration: InputDecoration(
hintText: "Bir not ekleyin",
border: InputBorder.none,
// border: OutlineInputBorder(
// borderRadius:
// BorderRadius.all(Radius.circular(20.0)),
// ),
),
),
),
),
),
),
I have an authentication screen like this:
#override
Widget build(BuildContext context) {
final bottom = MediaQuery.of(context).viewInsets.bottom;
return Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
reverse: true,
child: Padding(
padding: EdgeInsets.only(bottom: bottom),
child: Column(
children: <Widget>[
SizedBox(height: 48),
Image.asset(
"assets/images/logo.png",
width: 132,
),
SizedBox(height: 48),
Form(
child: Column(
children: <Widget>[
AuthTextFormField(
icon: Icons.email_outlined,
labelText: 'Email',
keyboardType: TextInputType.emailAddress,
),
AuthTextFormField(
icon: Icons.lock_outline,
labelText: 'Password',
obscureText: true,
),
],
),
),
],
),
),
),
);
}
I have followed this answer, but it still did not work for me. The keyboard still covered the text field. Any idea?
Thank you.
[UPDATE]
I use the code written in the answer above (by Jay Jay). And, this is the screenshot:
Its covered like this:
This Code works fine for me, I have removed the image and added a Container on its place with some height.
Also I have made some changes to your Code,
Scaffold(
resizeToAvoidBottomPadding: true,
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(bottom: bottom),
child: Column(
children: <Widget>[
SizedBox(height: 48),
Container(
color: Colors.blue,
height: 500,
),
SizedBox(height: 48),
Form(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.email), labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
),
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.lock_outline),
labelText: 'Password'),
obscureText: true,
),
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.email), labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
),
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.email), labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
),
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.email), labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
),
],
),
),
],
),
),
),
);
After trying it out, I think you should just add a height to your image.asset or better use a Container and specify the image in its decoration property and give the container a fixed height. It should all work correctly.
Here my code which works:
return Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
reverse: true,
child: Padding(
padding: EdgeInsets.only(bottom: bottom),
child: Column(
children: <Widget>[
SizedBox(height: 48),
Container(
height: 300,
color: Colors.red,
),
SizedBox(height: 48),
Form(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
icon:Icon(Icons.email),
labelText: 'Email'
),
keyboardType: TextInputType.emailAddress,
),
TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.lock_outline),
labelText: 'Password'
),
obscureText: true,
),
],
),
),
],
),
),
),
);
I don't understood what's happening, but when the form got erros the helper text message is moving the TextFormField. I tried increasing the height but I could not fix.
Anyone knows what's happening?
Look the image:
Follow the code:
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
alignment: Alignment.centerRight,
child: CountryCodePicker(
showFlagMain: true,
onChanged: print,
initialSelection:
I18n.of(context).locale.countryCode,
favorite: ['+55', 'BR'],
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
textStyle: TextStyle(
color: Colors.white, fontSize: 19.0),
flagWidth: 40.0,
)),
Container(
width: 200,
alignment: Alignment.center,
child: TextFormField(
keyboardType: TextInputType.phone,
controller: _phoneTextController,
inputFormatters: [
MaskTextInputFormatter(
mask: "(##) #####-####",
filter: {"#": RegExp(r'[0-9]')})
],
autocorrect: false,
autofocus: false,
style: TextStyle(
color: Colors.white, fontSize: 19.3),
cursorColor: Colors.yellow,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: '(99) 99999-9999',
filled: true,
hintStyle: TextStyle(color: Colors.grey)),
validator: (String value) =>
phoneValidator(value),
))
],
),
SizedBox(height: 20),
RaisedButton(
child: Text('Send'),
onPressed: () {
if (this._form.currentState.validate()) {
print(this._unmask(this._phoneTextController.text));
}
},
)
],
Thanks.
Try to wrap the container in an expanded widget.
You can modify the crossAxisAlignment of your Row to CrossAxisAlignment.start and the TextFormField widgets will be aligned when showing error text. A sample of this is below.
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 250,
child: TextFormField(
validator: (value) {
if (value.isEmpty) {
return '$firstName must not be empty.';
}
return null;
},
controller: firstNameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: firstName,
),
),
),
Container(
width: 250,
child: TextFormField(
validator: (value) {
if (value.isEmpty) {
return '$lastName must not be empty.';
}
return null;
},
controller: lastNameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: lastName,
),
),
)
]),
),
I'm trying to putting the country code before the phone number.
I usedcountry_pickers package but something gone wrong with my code,
my TextField's hintText visibility has gone, it's showing nothing
here is my widget
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: new Container(
padding: const EdgeInsets.only(left: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.blue)
),
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Phone Number",
prefix: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
print("${country.name}");
},
),
),
onChanged: (value){
this.phoneNo=value;
},
),
),
),
here's widget method for country code
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
The right way to use this is in Row widget. Prefix won't work here.
Row(
children: <Widget>[
Expanded(
child: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
print("${country.name}");
},
),
),
Expanded(
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Phone Number",
),
onChanged: (value) {
// this.phoneNo=value;
print(value);
},
),
),
],
),
I added TextFormField validation message..Everything working good. But All text not displayed.
Container(
padding: EdgeInsets.all(16.0),
margin: EdgeInsets.only(top: 30.0),
child: TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'The password you entered does not meet the minimum requirement. Please refer the Password Policy for more details.';
},
obscureText: true,
controller: confirmPasswordController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(20.0),
labelText: AppTranslations.of(context)
.text("passwordpage_username"),
),
),
),
Try this code
Expanded(
child: Container(
padding: EdgeInsets.all(16.0),
margin: EdgeInsets.only(top: 30.0),
child: TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'The password you entered does not meet the minimum requirement.\n Please refer the Password Policy for more details.';
},
obscureText: true,
controller: confirmPasswordController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(20.0),
labelText: AppTranslations.of(context)
.text("passwordpage_username"),
),
),
)
),