can you please let me know how we can remove a small margin from the text field label widget? also, can we add a different design for the label?
1.can we set different design label widgets to display vertically in the center of the text field? I want to show normal text in the center and when I tap on the text field then shows the label with a border.
2.Is there any method available to remove the extra margin from the label widget?
Here is below textField widget.
TextFormField(
validator: (value) {
return (value == null || value.isEmpty)
? 'Please Enter Password'
: null;
},
controller: tfPasswordController,
decoration: inputDecoration('Password', Icons.lock),
),
Here is the Input decoration
InputDecoration inputDecoration(String labelText, IconData iconData,
{String? prefix, String? helperText}) {
return InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
// helperText: helperText,
// labelText: labelText,
labelStyle: const TextStyle(color: Colors.black),
fillColor: Colors.blue,
filled: true,
prefixText: prefix,
prefixIcon: Icon(
iconData,
size: 20,
),
alignLabelWithHint: false,
label: Container(
padding: EdgeInsets.zero,
decoration: BoxDecoration(color: Colors.green,borderRadius: BorderRadius.circular(20),
border: Border.all(width: 1)),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6.0,horizontal: 12),
child: Text(labelText),
)),
prefixIconConstraints: const BoxConstraints(minWidth: 60),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.black)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.black)),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.black)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.black)),
);
Try below code and set isDense: true, hope its help to you.
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0.0),
isDense: true,
labelText: "Email",
border: InputBorder.none,
),
),
Result->
Related
I want to remove this underline.
This is my input field
TextField(
decoration: InputDecoration(
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
hintText: label,
hintStyle: TextStyle(color: Colors.grey[400]),
fillColor: Colors.white,
filled: true,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide:
const BorderSide(color: AppColors.textGrey2, width: 0.5),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide:
const BorderSide(color: AppColors.textGrey2, width: 0.5),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide:
const BorderSide(color: AppColors.textGrey2, width: 0.5)),
),
obscureText: obscureText,
),
I need this output
try to remove the styling from the text, add this line to your TextField
style: TextStyle(decoration:TextDecoration.none),
Do you see the underline in the hint text of your TextField?
If you put a Material widget above in your widget tree this should go by default.
Otherwise you can set it in the TextStyle of your hintText
hintStyle: TextStyle(decoration: TextDecoration.none)
My problem is that I can't find how to remove the margin between a textfield and its maxlength display.
So here what I have:
Here what I would like to have:
Here the code I have:
TextField(
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(
vertical: 15,
horizontal: 15
),
filled: true,
fillColor: Colors.grey,
border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(4),
),
),
focusedBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(4),
),
),
),
maxLength: 50,
);
Could you please help me to resolve my problem?
I have a multiline TextField with a prefixIcon, so now the Icon is in the center vertically and hint text is at top left. I want both of them to be aligned, either at the top or in the center vertically.
The code used is
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: TextField(
maxLines: 3,
decoration: InputDecoration(
hintText: 'Bio',
prefixIcon: Icon(Icons.chrome_reader_mode),
fillColor: Colors.grey[200],
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(),
),
),
),
),
Although in your particular case problem can be solved by adding a newline character (hintText: '\nBio'), a better solution is to use labelText property instead of a hintText. By default label is aligned with the center of the TextField.
TextField(
maxLines: 3,
decoration: InputDecoration(
labelText: 'Bio',
prefixIcon: Icon(Icons.chrome_reader_mode),
fillColor: Colors.grey[200],
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(),
),
),
),
This is an ugly solution, but it works. Other solutions (e.g., setting the textAlignVertical to TextAlignVertical.center) don't work since the maxLines is not null.
Add a TextStyle to the hintText and set the height of the TextStyle to 2.8. You need to reduce this when the fontSize is bigger because the height will be multiplied by the fontSize to make the line height. I added a contentPadding to make sure the text doesn't overflow(because now the text begins from the center of the TextField).
TextField(
maxLines: 3,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 30),
hintText: 'Bio',
hintStyle: TextStyle(
height: 2.8,
),
prefixIcon: Icon(Icons.chrome_reader_mode),
fillColor: Colors.grey[200],
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(),
),
),
),
Result:
Widget customTextView(String hint, Icon iconName) {
return Container(
decoration: BoxDecoration(
color: _DarkWhiteColor.withOpacity(0.5),
borderRadius: BorderRadius.circular(5),
),
child: Padding(
padding: const EdgeInsets.only(left: 0, right: 0),
child: TextField(
style: TextStyle(color: Colors.grey),
cursorColor: Colors.grey,
decoration: InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
fillColor: _DarkWhiteColor.withOpacity(0),
filled: true,
hintText: "Enter Your Message",
labelStyle: TextStyle(color: Colors.white),
// suffixIcon: iconName,
prefixIcon: Container(
transform: Matrix4.translationValues(0, -45, 0),
child: iconName,
),
),
maxLines: 6,
),
),
);
}
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 want my TextField input to be on the same line as the prefix icon.
I tried many things including contentPadding but nothing worked.
I want the text to be in the middle of the shopping cart icon.
contentPadding just moves the whole thing instead of just text
child: TextField(
decoration: InputDecoration(
labelText: 'name of grocery item',
labelStyle: TextStyle(fontSize: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
// contentPadding: EdgeInsets.only(left:10),
contentPadding: EdgeInsets.only(top: 5, left: 25),
prefix: Padding(
padding: const EdgeInsets.only(top: 12.0),
child: Icon(Icons.local_grocery_store),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(color: Colors.green),
)
),
),
you can use the prefixIcon constructor in Textfield widget to achieve this as follows
TextField(
decoration: InputDecoration(
labelText: 'name of grocery item',
labelStyle: TextStyle(fontSize: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
// contentPadding: EdgeInsets.only(left:10),
contentPadding: EdgeInsets.only(top: 0, left: 25),
prefixIcon: Icon(Icons.local_grocery_store),),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(color: Colors.green),
)),
),
Remove conten padding top - 5 or put contentpadding.all(5)