How to position change flutter TextFormField prefix icon? - flutter

I have tried to change TextFormField prefix icon positions but I don't understand how to do it anyone has a any idea I'm used code as below
child: TextFormField(
autocorrect: false,
maxLines: 4,
decoration: InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(
style: BorderStyle.solid)),
hintStyle: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.1)),
prefixIcon: Icon(Icons.edit),
hintText: "Onion 1kg",
labelText: 'Item Description (Optional)',
),
style: TextStyle(
color: Color.fromRGBO(25, 25, 35, 1),
fontSize:18,
),
)

I think you are trying to change the icon position in your TextFormField to right position, so just use suffixIcon: Icon(Icons.edit), instead of prefixIcon: Icon(Icons.edit), so your code will be come like below:
child: TextFormField(
autocorrect: false,
maxLines: 4,
decoration: InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(
style: BorderStyle.solid)),
hintStyle: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.1)),
//prefixIcon: Icon(Icons.edit), // this is left side
suffixIcon: Icon(Icons.edit), // this is right side.
hintText: "Onion 1kg",
labelText: 'Item Description (Optional)',
),
style: TextStyle(
color: Color.fromRGBO(25, 25, 35, 1),
fontSize:18,
),
)

prefixIcon: Padding(
padding: EdgeInsetsDirectional.only(start: 20),
child: Image.asset(
"assets/images/user-form-icon.svg",
), // myIcon is a 48px-wide widget.
),
Does this try what you want? Or you can use
prefix: Container () directly

Related

Error message showing inside the text form field in Flutter

I have implemented a text form field with validation, and it returns the error message but it gets displayed inside the text form field. Is there a way to show it outside the text form field?
Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(
horizontal: 20),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.1),
borderRadius: const BorderRadius.all(
Radius.circular(10))),
child: TextFormField(
autovalidateMode:
AutovalidateMode.onUserInteraction,
controller: _controller,
validator: validatePhone,
textAlignVertical: TextAlignVertical.center,
style: const TextStyle(
color: primaryText,
fontFamily: 'InterMedium',
fontSize: 15),
decoration: const InputDecoration(
counterText: '',
errorStyle: TextStyle(
fontFamily: 'InterMedium',
),
prefixIcon: Padding(
padding: EdgeInsets.only(
left: 20, right: 15),
child: Icon(
Icons.phone_android_rounded,
color: secondaryText,
),
),
hintText: 'Enter mobile number',
hintStyle: TextStyle(
fontFamily: 'InterMedium',
color: secondaryText,
),
border: InputBorder.none,
),
cursorColor: secondaryColor,
maxLines: 1,
maxLength: 10,
keyboardType: TextInputType.phone,
textInputAction: TextInputAction.done,
),
),
How it is now -
How I want it to look like -
Remove parent widget Container and add decoration property of TextFormField like below example !
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
cursorColor: Colors.black,
validator: validator,
controller: controller,
keyboardType: TextInputType.phone,
style: const TextStyle(fontSize: 16, color: Colors.black, fontFamily: 'Helvetica', fontWeight: FontWeight.normal),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
hintText: hint)),
),
P.S :- If you want to add grey color in your TextFormField then you may use decoration: InputDecoration(fillColor: Colors.grey, filled: true) !

add padding to TextField cursor / center the TextField cursor in flutter

I have a TextField and when i change cursor height it comes down . i want it come center or add padding under it.
Cursor should be vertically center of TextField is that possible ?
and this is my code.
TextField(
cursorHeight: 30,
cursorColor: Colors.yellow,
cursorWidth: 2,
cursorRadius: Radius.circular(500),
style: TextStyle(color: Colors.white, fontSize: 14),
obscureText: isPasswordTextField ? showPassword : false,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(8)),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.yellow),
borderRadius: BorderRadius.circular(10),
),
suffixIcon: isPasswordTextField
? IconButton(
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
icon: Icon(
Icons.remove_red_eye,
color: Colors.yellow,
),
)
: null,
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
filled: true,
fillColor: Color.fromRGBO(28, 28, 28, 1),
labelText: labelText,
labelStyle: TextStyle(
color: Colors.yellow,
fontSize: 22,
fontFamily: 'Exo',
fontWeight: FontWeight.bold
),
floatingLabelBehavior: FloatingLabelBehavior.always,
hoverColor: Color.fromRGBO(54, 54, 54, 1),
hintText: placeholder,
hintStyle: TextStyle(
fontSize: 14,
color: Colors.white,
)
),
),
This should help. As you can see in the your textfiled there is no height specified.
TextField(
cursorHeight: 30,
cursorColor: Colors.yellow,
cursorWidth: 2,
cursorRadius:const Radius.circular(500),
style: TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.5 //Add this
),
),
Try below code hope its helpful to you.add your extra code also I tried to design
TextField(
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Colors.yellow,
),
borderRadius: BorderRadius.circular(10),
),
suffixIcon: IconButton(
onPressed: () {
setState(() {});
},
icon: Icon(
Icons.remove_red_eye,
color: Colors.yellow,
),
),
// floatingLabelBehavior: FloatingLabelBehavior.always,
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
filled: true,
fillColor: Color.fromRGBO(28, 28, 28, 1),
labelText: 'labelText',
labelStyle: TextStyle(
color: Colors.yellow,
fontSize: 22,
fontFamily: 'Exo',
fontWeight: FontWeight.bold),
hoverColor: Color.fromRGBO(54, 54, 54, 1),
hintText: 'placeholder',
hintStyle: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
Your result screen->

flutter padding to text in textfield

I have given the textfield a custom height with a container around it. The icons are stlii in the middle but the text is not in the center of the textfield. Do somebody know a way to fix this problem?
Container(
height: 45,
child: TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[100],
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
hintText: 'Hint Text',
),
style: TextStyle(
fontSize: 18,
),
),
),
For horizontally centered hint text: The hint text aligns according to the TextFormField's textAlign, so adding textAlign: TextAlign.center to the TextFormField will center the hint text horizontally.
For vertically centered hint text: Add a contentPadding, e.g., contentPadding: EdgeInsets.symmetric(vertical: 2) to the TextField.
Container(
height: 45,
child: TextFormField(
textAlign: TextAlign.center, // this is new
decoration: InputDecoration(
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 2), // this is new
fillColor: Colors.grey[100],
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
hintText: 'Hint Text',
),
style: TextStyle(
fontSize: 18,
),
),
),

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),
),
),