Text cutting from below in TextField widget: Flutter - flutter

TextField widget works fine with less text but when i adding long text it starts to cut from bottom.
Without text.
With less text
Problem starts here with long text
My widget code.
Opacity(
opacity: 0.5600000023841858,
child: Container(
padding: EdgeInsets.only(left: 10),
width: 213,
height: 36,
decoration: BoxDecoration(
color: boxShadowCreamColor,
borderRadius: BorderRadius.circular(48),
boxShadow: [BoxShadow(color: boxShadowColor, offset: Offset(0, 0), blurRadius: 8, spreadRadius: 0)],
),
child: TextField(
keyboardType: TextInputType.text,
textAlign: TextAlign.left,
maxLines: 1,
textAlignVertical: TextAlignVertical.center,
style: TextStyle(color: Colors.white,fontSize: fontMedium,fontWeight: fontWeightRegular),
decoration: InputDecoration(
hintText: "Search",
border: InputBorder.none,
hintStyle: TextStyle(color: Colors.white,fontSize: fontMedium,fontWeight: fontWeightRegular),
suffixIcon: Icon(
Icons.search,
color: Colors.white,
),
),
),
),
);

Use isDense property inside decoration and set it to true, which should resolve your issue.
isDense property helps to take less vertical space.
decoration: InputDecoration(
isDense: true,
hintText: "Search",
border: InputBorder.none,
hintStyle: TextStyle(color: Colors.white),
suffixIcon: Icon(
Icons.search,
color: Colors.white,
),
),

It happens just because of your height which you have given your Container. Just increase that it will be fine for you.
try height: 42, // -- its because textfield shrink the size of Textfield when its growing.
OR
Add isDense: true // inside InputDecoration

Related

Label Text in TextField wont center?

I'm attempting to center my labelText in a TextField, but I cannot get it to center for the life of me. Anyone see a glaringly obvious issue that would be causing this? Thanks!
Container(
width:
MediaQuery.of(context).size.width * .85,
height:
MediaQuery.of(context).size.height * .12,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(12))),
child: TextField(
textAlign: TextAlign.center,
controller: _notesEditingController,
obscureText: false,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 40.0),
fillColor: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(12.0)),
),
labelText: 'notes',
labelStyle: TextStyle(
color: Color.fromRGBO(105, 105, 105, 10),
)),
),
),
Please try this, replace labelText and use hintText
Container(
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: 'Center the text',
),
),
)

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

TextField placeholder and text vertical alignment is not right

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

How to position change flutter TextFormField prefix icon?

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

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