Custom TextField Designs Flutter - flutter

I want to achieve the design below but I don't know how to customize this, am still a newbie in Flutter.
I know how to use TextFields but don't know how to go around this :

Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[700]),
hintText: "Email",
fillColor: Colors.white70),
),
SizedBox(height: 50),
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[700]),
hintText: "Password",
fillColor: Colors.white70),
)
]));

Lutaaya Huzaifah Idris Refer to the documentation as specified by Afridi Kayal in comments for more customization.
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.only(left: 25, right: 20),
margin: const EdgeInsets.fromLTRB(20,10,20,10),
child: TextField(
decoration: InputDecoration(
hintText: "Email",
border: InputBorder.none,
),
),
),
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.only(left: 25, right: 20),
margin: const EdgeInsets.fromLTRB(20,10,20,10),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
border: InputBorder.none,
),
obscureText: true,
),
),
Output:

Related

How could show an error message from a textformfield's validator (which is inside Container)?

I have the following issue.
I have a TextFormField where the user has to put some data (for example his email).
I am using a validator , but when the error raises from the TextFormField's validator, the error message and my TextFormField's values are not show properly.
Here is the code:
Container(
height: 60,
margin: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
border: Border.all(
color: const Color(0xFF59C48C),
width: 2.0,
style: BorderStyle.solid),
),
child: Container(
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Center(
child: Container(
child: Image.asset("images/email.png",
width: 30, height: 30))),
const SizedBox(
width: 10,
),
Expanded(
child: Center(
child: TextFormField(
validator: (mail) =>
bloc.mailValidator(mail ?? "")
? null
: "Invalid Email",
obscureText: false,
controller: _emailController,
keyboardType:
TextInputType.emailAddress,
style: const TextStyle(
color: Colors.black),
decoration: const InputDecoration(
hintText: "Email",
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 20,
),
labelStyle: TextStyle(
color: Colors.black,
fontSize: 20,
),
),
),
),
),
]),
),
),
),
),
I would like to show the error beside the expanded TextFormField or on the border of it like the image below.
Thank you in advance!
Use OutlineInputBorder with label or labelText
decoration: const InputDecoration(
hintText: "Email",
labelText: "Email",
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(),
errorBorder: OutlineInputBorder(),
disabledBorder: OutlineInputBorder(),
TextFormField(
autovalidateMode: AutovalidateMode.always,
validator: (mail) {
return "Enter dasdasd"; //handle the error text
},
obscureText: false,
keyboardType: TextInputType.emailAddress,
style: const TextStyle(color: Colors.black),
decoration: const InputDecoration(
hintText: "Email",
labelText: "Email",
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(),
errorBorder: OutlineInputBorder(),
disabledBorder: OutlineInputBorder(),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 20,
),
),
),

Flutter how to add padding in TextFormField?

I hope the title is enough to understand what i want, How to add padding and margin in TextFormField? please see picture below for more information. thanks
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo.png'),
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your username'),
),
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
],
)
You can use several methods to increase the distance from them:
SizedBox()
Padding()
Container(margin , child: ...)
1- SizedBox():
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo.png'),
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your username'),
),
SizedBox(height:10), // will add 10 pixels
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
],
)
2- Padding()
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your username'),
),
),
3- Container()
Container(
margin: EdgeInsets.only(top: 15),
child: TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
),
Please wrap TextFormField in the Container and set margin like as top, left, right, bottom according your ui. Please check this and If this it's correct so please tell me.
Container(
margin: EdgeInsets.only(top: 10,left: 0,right: 0,bottom: 0),
child: TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
),
To apply horizontal padding just add Padding widget above your Column:
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/logo.png'),
// your text fields
],
...
To add vertical padding use SizedBox inside Column:
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo.png'),
TextFormField1(...),
SizedBox(height: 24.0),
TextFormField2(...),
SizedBox(height: 24.0),
],
)
InputDecoration takes a contentPadding value. Just use that directly.
you can add SizedBox.
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your username'),
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
You can insert sizedbox in between the textformfield like:-
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo.png'),
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your username'),
),
SizedBox(height:30), // will add 30 pixels gap in between the fields
TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
labelText: 'Enter your password'),
),
],
)

Add Dropdown menu to TextField Flutter

I have form where I collect data from client in flutter.
At the last 3 fields I want add dropdown menu with different choice to be done by the customers.
But I cant find how to add dropdown menu choice to the form flutter.
this is the screen shot:
enter image description here
the part of the code interested is:
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
SizedBox(width: 10,),
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
SizedBox(width: 10,),
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
],
),
), ```

Flutter wrong position of text in textfield after changing height

According to my design I have a TextField with 30pt of height.
Here's how I am trying to do that:
Container(
height: 30,
child: new TextField(
textAlign: TextAlign.start,
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(30.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[800]),
hintText: "Search",
fillColor: Colors.lightGreen),
)),
And here's the result:
How can I align hint and text vertically?
Set contentPadding to EdgeInsets.symmetric(horizontal: 0) in InputDecoration. This will remove the default horizontal padding for the Text:
Container(
height: 35,
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 0),
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(5.0),
),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[800]),
hintText: "Search",
fillColor: Colors.lightGreen),
),
),

How can I make rounded TextField in flutter?

Material Design for iOS doesn't look good, especially the TextField. So is there any way to create your own ? Or Is ther any way to add some styling to TextField so it will look rounded ?
You can add rounded corners to a TextField within the decoration parameter of it
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[800]),
hintText: "Type in your text",
fillColor: Colors.white70),
)
#Rockvole answer is correct but just in case u don't like the default border around the TextField, you can achieve it by overriding the borderSide attribute of the OutlineInputBorder like this:
TextField(
textAlign: TextAlign.center,
controller: searchCtrl,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: 'Enter a product name eg. pension',
hintStyle: TextStyle(fontSize: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
filled: true,
contentPadding: EdgeInsets.all(16),
fillColor: colorSearchBg,
),
),
You can get desired output with the help of Container Have a look..
new Container(
child: new Text (
"Text with rounded edges.",
style: new TextStyle(
color: Colors.blue[500],
fontWeight: FontWeight.w900
)
),
decoration: new BoxDecoration (
borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
color: Colors.black
),
padding: new EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0),
),
You can try this code bellow:
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
)
I've collected this solution from several methods and solutions over the internet, it works very well with me, so it could help someone out there:
This solution will control the width and height of the TextField, and other properties
Container(
child: Theme(
data: Theme.of(context).copyWith(splashColor: Colors.transparent),
child: TextField(
autofocus: false,
style: TextStyle(fontSize: 15.0, color: Color(0xFFbdc6cf)),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Search',
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 12.0, top: 0.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
),
),
),
decoration: new BoxDecoration (
borderRadius: new BorderRadius.all(new Radius.circular(30.0)),
color: Colors.white ), width: 250, height: 50, margin: new EdgeInsets.fromLTRB(20, 20, 20, 210), padding: new EdgeInsets.fromLTRB(8, 8, 8, 8),
),
You could approach the purpose in a few different ways:
First Approach:
Container(
child: new Text (
"Some Text",
style: TextStyle(
color: Colors.black
)
),
decoration: BoxDecoration (
borderRadius: BorderRadius.all( Radius.circular(15)),
color: Colors.white
),
padding: EdgeInsets.all(16.0),
),
Second Approach:
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(15.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[600]),
hintText: "Hint text",
fillColor: Colors.white),
)
Third Approach:
TextField(
textAlign: TextAlign.center,
controller: someTextXontroller,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: 'Hint Text',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
filled: true,
contentPadding: EdgeInsets.all(16),
fillColor: Colors.blue,
),
),
Try this in TextFormField:
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),