How to remove TextFormField default bottom padding in flutter - flutter

How can I remove the default bottom padding from the TextFormField?
I try to remove all default padding it didn't work.
Expanded(
child:AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.blue,
child: TextFormField(
scrollPadding: EdgeInsets.zero,
focusNode: pin1FocusNode,
style: const TextStyle(fontSize: 20),
maxLength: 1,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
counter: const Offstage(),
contentPadding:
EdgeInsets.zero,
border: outlineInputBorder(),
focusedBorder: outlineInputBorder(),
enabledBorder: outlineInputBorder(),
),
onChanged: (value) => nextField(value, pinFocusNode),
),
)))

You can not remove this padding, you can do one thing, you can remove the underline from TextFormField and but border under the container., it may be easy. And instead of using Expanded and AspectRatio just put some height and width in the container.

Related

How do I make a TextField take up the entire screen

I am creating a notes application and using a text field with max lines set as null so the text can expand infinitely according to the text. The problem is that you can only start typing in the note when you select the text field due to its size I want to make it big enough to cover the entire screen for accessibility but I fear that the size of the text field may differ on each device which would ruin the entire point of making it fit the entire screen.
TextField(
controller: _textController,
style: const TextStyle(color: Colors.white),
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
border: InputBorder.none,
hintText: "Start typing your note...",
hintStyle: TextStyle(color: Colors.white),
),
);
By wraping your TextField in a SizedBox with a height: double.infinity you can expand your TextField
SizedBox(
height: double.infinity,
child: TextField(
controller: _textController,
style: const TextStyle(color: Colors.white),
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
border: InputBorder.none,
hintText: "Start typing your note...",
hintStyle: TextStyle(color: Colors.white),
)),
),
SizedBox(
height: MediaQuery.of(context).size.height,
TextField(
controller: _textController,
style: const TextStyle(color: Colors.white),
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
border: InputBorder.none,
hintText: "Start typing your note...",
hintStyle: TextStyle(color: Colors.white),
),
),
),

How to Create small TextField

I want to reduce space between line and text with flutter.
SizedBox(
width: 60.0,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: '125',
),
),
),
Instead of wrapping TextField inside SizedBox use constraints property of Input Decoration to give the TextField min or max height/width:
TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: '125',
isDense: true,
constraints: BoxConstraints(
maxWidth: 60
)
),
)
Inside InputDecoration() set the contentPadding: EdgeInsets.zero. And set isDense: true

How to disable TextFormField default animation

I want to disable the default behavior when a user focus on the text field, where the label text gets smaller and docks to the upper left :
I want to disable this behavior and only make the label text disappear, how can I do it?
Use FloatingLabelBehavior.never inside InputDecoration will help you hiding your label and instead of labelText you can use hintText so it becomes disappear when you type something.
TextFormField(
decoration: InputDecoration(
hintText: "Search",
floatingLabelBehavior: FloatingLabelBehavior.never,
border: InputBorder.none,
suffixIcon: Icon(
Icons.search,
),
),
),
Try out this
TextFormField(
cursorColor: Colors.black,
keyboardType: TextInputType.text,
decoration: new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding:
EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
hintText: "Hints"),
)
And customize textfield decoration as you desired.
You can actually add a leading widget inside TextFormField where you can put the country picker.
Row(
children: <Widget>[
Expanded(
child: FormBuilderTextField(
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(context),
FormBuilderValidators.minLength(context, 9),
FormBuilderValidators.maxLength(context, 9),
FormBuilderValidators.numeric(context),
]),
name: "mobile_number",
keyboardType: TextInputType.phone,
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: CountryPickerDropdown(
initialValue: 'AU',
itemBuilder: _buildDropdownItem,
itemFilter: (c) => [
'AU',
'PH',
].contains(c.isoCode),
priorityList: [
CountryPickerUtils.getCountryByIsoCode('AU'),
CountryPickerUtils.getCountryByIsoCode('PH'),
],
sortComparator: (Country a, Country b) =>
a.isoCode.compareTo(b.isoCode),
onValuePicked: (Country country) {
print("${country}");
},
),
),
labelText: 'Mobile #',
floatingLabelBehavior: FloatingLabelBehavior.never,
),
)),
],
),

Flutter TextField hint text not aligned center horizontally

I have a very simple TextField, where I have textAlign: TextAlign.center inside (as advised in other answer here).
However, hint text is not horizontally centered, whereas input text is centered. (see attached picture)
I wonder why.. Somebody please help.
Code:
Container(
margin: EdgeInsets.symmetric(horizontal: 18.0),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'time',
),
),
width: 80,
)
You have to use hintText instead of labelText:
Container(
margin: EdgeInsets.symmetric(horizontal: 18.0),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'time', //instead of labelText
),
),
width: 80,
)

Text cutting from below in TextField widget: 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