errorText flutter issue - flutter

I build the widget with TextField but error text is shows inside the field.
The widget is:
child: TextField(
maxLines: 1,
controller: textEditingController,
style: TextStyle(
fontFamily: ConstantData.fontFamily,
color: ConstantData.textColor,
fontWeight: FontWeight.w400,
fontSize: fontSize),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: ConstantWidget.getWidthPercentSize(context, 2)),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: 'name',
errorText: 'errorText',
hintStyle: TextStyle(
fontFamily: ConstantData.fontFamily,
color: ConstantData.textColor,
fontWeight: FontWeight.w400,
fontSize: fontSize)),
),
Where is my mistake to show the text inside of field, not below them?
Thanks a lot.

I think you have wrapped the TextField with a Container of grey color.
Please remove it and add fillColor and filled properties to the InputDecoration() to color the TextField.
For example:
decoration: InputDecoration(
...
filled: true,
fillColor: Colors.grey, // Any color you want
...
)

Related

flutter how remove text underline on text selection (TextFormField)?

It is necessary to move the cursor to the end of the text, but in flutter this is strangely implemented through text selection, I do it like this
textController.selection =
TextSelection.collapsed(offset: textController.text.length);
it works, but when typing, it appears underlined
It is possible to somehow remove the underlining of the text, I read the documentation, but did not find it.
My TextFormField
TextFormField(
cursorColor: Colors.white,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
),
controller: textController,
autofocus: false,
decoration: const InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
filled: true,
isDense: true,
hintText:
'search',
hintStyle: TextStyle(
//Style of hintText
color: Colors.white60,
fontSize: 20,
),
),
),
This might help you:
TextField(
style: const TextStyle(
decoration: TextDecoration.none),
),

Flutter TextField label is outside of background when focused

Title should say everything. Nevertheless, here are some pictures for better understanding.
How it should look like (Google Material Components):
How it actually looks like:
But please ignore the bottom border of the pic "how it should look like". The problem is just that the label is outside of the background.
And also the Text and LabelText is not vertically centered. Another picture:
I also tried playing around with the paddings (top and bottom) but either it didn't change anything or I got an error.
And here is the source code:
return TextField(
onChanged: (String? value) {
print(value);
onChanged(value);
},
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: labelText,
labelStyle: TextStyle(
fontWeight: FontWeight.w700,
color: kInputColor,
fontSize: 14.0,
),
filled: true,
fillColor: kInputFillColor,
contentPadding: EdgeInsets.only(
top: 14.0,
bottom: 14.0,
left: 14.0,
right: 14.0,
),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6.0),
),
),
cursorWidth: 1.5,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black,
fontSize: 14.0,
),
);
The problem was the type of border I used. Through the answer of #Diwyansh, I found out that the default border a TextField uses is the UnderlineInputBorder. I found out that this type of border also has the properties to set borderRadius and borderSide. So when I use UnderlineInputBorder instead of OutlineInputBorder (which for me sounded more meaningful than UnderlineInputBorder), the label is drawn within the background of the TextField. This is how my source code looks now:
return TextField(
onChanged: (String? value) {
print(value);
onChanged(value);
},
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: labelText,
labelStyle: TextStyle(
fontWeight: FontWeight.w700,
color: kInputColor,
fontSize: 14.0,
),
filled: true,
fillColor: kInputFillColor,
contentPadding: EdgeInsets.only(
top: 14.0,
bottom: 12.0,
left: 14.0,
right: 14.0,
),
border: UnderlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide.none,
),
),
cursorWidth: 1.5,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black,
fontSize: 14.0,
),
);
You can get it InputDecoration Property
TextFormField(
decoration: InputDecoration(
labelText: "Label",
filled: true),
)
According to The Official Flutter Documentation of OutlineInputBorder https://api.flutter.dev/flutter/material/OutlineInputBorder/OutlineInputBorder.html
InputDecoration.floatingLabelBehavior, which should be set to FloatingLabelBehavior.never when the borderSide is BorderSide.none. If let as FloatingLabelBehavior.auto, the label will extend beyond the container as if the border were still being drawn.
Which means if BorderSide is set to BorderSide.none, just like you did, the label would look outside the background container when focused.
so you just need to set floatingLabelBehavior to FloatingLabelBehavior.never.
which would make it work like hintText

Underline multiple lines in single TextField - Flutter/Dart

Looking to have a TextField which has multiple rows but also an underline for each row. When typing text it should continue to the next row without needing the return key.
Current:
TextField(
maxLines: 2,
decoration: InputDecoration(
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid),
),
),
)
Current Output:
Desired Output:
this will work for you I guess
TextField(
keyboardType: TextInputType.multiline,
minLines: 100,
maxLines: 500,
style: TextStyle(
decoration: TextDecoration.underline,
),
decoration: InputDecoration(
enabledBorder: InputBorder.none,
hintText: 'Notes.....',
hintStyle: TextStyle(color: Colors.black87),
),
),
If you'd still like to change the color or type or density of the underline use the decorationStyle,decorationColor, and decorationThickness properties.

Underlined When Writing - Flutter - Textfield

Whenever I write the word is underlined. As soon as I write a new word, it will no longer be underlined, but what I am currently writing. Can I somehow issue that nothing is underlined when writing? I didn't find anything in the forum either.
child: TextField(
autocorrect: false,
style: TextStyle(
fontSize: 22.0,
),
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: 'Search',
border: InputBorder.none,
icon: Icon(
Icons.search,
color: Color(0xFFe1F5FE),
),
),
),
did you try it with focusedBorder?
TextField(
decoration: new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
hintText: 'what you want'
),
),
Put this code inside TextField
keyboardType: TextInputType.text,
Example:
TextField(
keyboardType: TextInputType.text,
autocorrect: false,
style: TextStyle(
fontSize: 22.0,
),
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: 'Search',
border: InputBorder.none,
icon: Icon(
Icons.search,
color: Color(0xFFe1F5FE),
),
),
),

How to add underlines to a multiline input in Flutter?

so this displays an underline under a single TextField
TextField(
decoration: InputDecoration(
hintText: 'Notes.....',
hintStyle: TextStyle(color: Colors.black87),
border: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black87,
width: 1.0, style: BorderStyle.solid)
But when I do this
TextField(
keyboardType: TextInputType.multiline,
minLines: 100,
masLines: 500,
decoration: InputDecoration(
hintText: 'Notes.....',
hintStyle: TextStyle(color: Colors.black87),
border: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black87,
width: 1.0, style: BorderStyle.solid)
It disappears? Is there anyway to have the lines show up?
This will work.
TextField(
keyboardType: TextInputType.multiline,
minLines: 100,
maxLines: 500,
style: TextStyle(
decoration: TextDecoration.underline,
),
decoration: InputDecoration(
enabledBorder: InputBorder.none,
hintText: 'Notes.....',
hintStyle: TextStyle(color: Colors.black87),
),
),
If you'd still like to change the colour or type or density of the underline use the decorationStyle ,decorationColor and decorationThickness properties.
:)