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),
),
),
Related
I want to change the Color of an textfield in flutter.
Means the area within the InputBorder.
I tried to wrap the textfield in container, and change the color of the container, but this seems a fool's step to solve the problem.
I tried the fillColor option, but nothing changed.
Here is my Code -->
Container(
padding: EdgeInsets.fromLTRB(
10,
screenHeight * 0.016415869,
10,
0,
),
height: screenHeight * 0.082079343,
child: TextField(
cursorColor: Color(0xFF7675E0),
textAlign: TextAlign.left,
decoration: InputDecoration(
fillColor: Colors.black, //Nothing Worked
contentPadding: EdgeInsets.fromLTRB(
15,
screenHeight * 0.002735978,
2,
screenHeight * 0.002735978,
),
hintText: "Search",
hintStyle: GoogleFonts.sniglet(
fontSize: screenHeight * 0.020519836,
color: Color(0xFFC6C8CA),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color: Colors.grey[200].withOpacity(0.2),
),
),
prefixIcon: Icon(Icons.search),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[200].withOpacity(1),
),
),
),
),
),
Thanks in Advance :)
Try out this:-
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey,
If you want to set the color to your text field then there is one boolean variable which you need to set true so your color will be added to your text field
Container(
child: TextField(
cursorColor: Color(0xFF7675E0),
textAlign: TextAlign.left,
decoration: InputDecoration(
fillColor: Colors.black, // you can change color of textfield
filled: true, // this should be true if you want to set color to textfield
hintText: "Search",
prefixIcon: Icon(Icons.search),
),
),
),
Basically you can leave your code as you provided us. The important missing value is
filled: true
With this value applied you can style the background color easy.
Reference to the doc: https://api.flutter.dev/flutter/material/TextField-class.html
don't use Container for TextField decoration, there are more property into TextField
TextField use
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
TextField(
controller: usernameController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
contentPadding: const EdgeInsets.all(24),
prefixIcon: Icon(Icons.person, color: Colors.white),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
),
),
I am developing a mobile application using Flutter. I am having an issue with aligning the text field's placeholder text and its value vertically centered.
This is my code for TextField.
return Container(
color: Colors.black,
child: Padding(
padding: EdgeInsets.all(10),
child: TextField(
onChanged: (text) {
this.filter = text.toLowerCase();
this._refreshListItems();
},
style: TextStyle(
height: 0.5
),
cursorColor: Colors.black12,
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(Icons.search, color: Colors.black26,),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
hintText: "Search",
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
),
),
)
);
However, when it is rendered, the placeholder and its value are getting a little bit to the top vertically as in the screenshots below.
What's wrong with my code and how can I fix it?
Using text style height to 0.5 is causing the text span to be half of the size of the font size. Remove it as don't think that will help you.
style: TextStyle(
height: 0.5
),
In order to handle content size you can play with contentPadding
decoration: InputDecoration(
contentPadding: EdgeInsets.all(1),
....
),
I used the following code and it is working
contentPadding: EdgeInsets.fromLTRB(0, 8, 0, 0),
if you set a custom height, try this.
Container(
height: 36,
child: TextField(
maxLines: 1,
style: TextStyle(fontSize: 17),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
filled: true,
prefixIcon:
Icon(Icons.search, color: Theme.of(context).iconTheme.color),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(30))),
fillColor: Theme.of(context).inputDecorationTheme.fillColor,
contentPadding: EdgeInsets.zero,
hintText: 'Search',
),
),
)
I am trying to build a form with custom textfield height, i would like to make the textfield text and hit text to be center vertically. Here is my code
SizedBox(
height: 40,
child:
TextField(
style: TextStyle(
fontSize: 14,
),
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.left,
maxLines: 1,
decoration: InputDecoration(
filled: true,
fillColor: Color(0xff5a9fd6).withOpacity(0.15),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff5a9fd6).withOpacity(1.0),
),
borderRadius: BorderRadius.circular(2.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.transparent,
),
borderRadius: BorderRadius.circular(1.0),
)
),
)
),
When i decrease the font size then the text is aligned vertically but i would like to use the font size as 14 and above.
Do not wrap the TextField from SizeBox to manage the height of the TextField. You can do this by using vertical contentPadding as follows. It keeps your text in the center.
TextField(
style: TextStyle(
fontSize: 14,
),
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.left,
maxLines: 1,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 50, horizontal: 20),
filled: true,
fillColor: Color(0xff5a9fd6).withOpacity(0.15),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff5a9fd6).withOpacity(1.0),
),
borderRadius: BorderRadius.circular(2.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.transparent,
),
borderRadius: BorderRadius.circular(1.0),
)
),
),
You can set the contentPadding of the TextField as 0 or according to your requirement.
SizedBox(
height: 40,
child:
TextField(
style: TextStyle(
fontSize: 14,
),
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.left,
maxLines: 1,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(0),
filled: true,
fillColor: Color(0xff5a9fd6).withOpacity(0.15),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff5a9fd6).withOpacity(1.0),
),
borderRadius: BorderRadius.circular(2.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.transparent,
),
borderRadius: BorderRadius.circular(1.0),
)
),
)
),
You can to adjust contentPadding to center your text vertically, for example:
TextField(
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(<your value>),
)
When keyboard pops up, there will be bottom over flowed. I need to add a expanded card as background for login form and submit button.
And also need that expanded card to move up when there is keyboard.
I have checked through many other solution for keyboard popup, but I couldn't get exact solution for mine design.
return new Scaffold(
body: new Column(children: <Widget>[
SizedBox(
height: 70,
),
new Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
),
new Text(
"Login",
style: TextStyle(fontSize: 20, color: Colors.white),
),
new Text(
"It has noon , but also the Type roman, remaining essentially unchanged for the wish i could do.",
textAlign: TextAlign.center,
),
Column(
children: <Widget>[
Expanded(
child: Container(
child: Container(
padding: EdgeInsets.all(24),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(25.0),
topRight: const Radius.circular(25.0))),
child: new ListView(
children: <Widget>[
TextField(
style: new TextStyle(
color: Color(0xff651515),
),
autofocus: false,
obscureText: false,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "email",
hintText: "email",
labelStyle: TextStyle(
color: Color(0xffa4a4a4),
fontSize: 14,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 2,
color: Color(0xff55c882),
style: BorderStyle.solid),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffa4a4a4),
),
),
),
),
SizedBox(
height: 20,
),
TextField(
style: new TextStyle(
color: Color(0xff651515),
),
autofocus: false,
obscureText: false,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "password",
hintText: "password",
labelStyle: TextStyle(
color: Color(0xffa4a4a4),
fontSize: 14,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 2,
color: Color(0xff55c882),
style: BorderStyle.solid),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffa4a4a4),
),
),
),
),
],
),
),
))
],
)
]));
you can just wrap your column with a:
SingleChildScrollView(
child: put your column here
)
hope it helped
I have a rounded textfield. It works well, but when the user taps on it, a grey color background appears. How can I disable that splash effect?
This is my code and result:
new Container(
margin: const EdgeInsets.only(left: 30.0, top: 60.0, right:
30.0),
height: 40.0,
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.all(new Radius.circular(25.7))
),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new TextField(
controller: null,
autofocus: false,
style:
new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding: const EdgeInsets.only(
left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
),
))),
It looks like it's caused by the splash effect on the textfield. I couldn't find a way to disable it for that specific widget but you can make it transparent by wrapping your TextField in a Theme widget and setting the splashColor to transparent:
Theme(
data: Theme.of(context).copyWith(splashColor: Colors.transparent),
child: TextField(
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.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),
),
),
),
);
“Flutter Textfield background color”
*Change border color of TextField in flutter
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(25.0),
),
),
)
text fieldform color flutter
TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)
Flutter TextFormField background color
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
filled: true, // dont forget this line
...
)
...
)
Flutter textfield label color
labelStyle: TextStyle(
color: Colors.white,
)
Color textfield text flutter
TextField(
style: TextStyle(color: Colors.white),
...
)
use BorderSide.none as:
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),