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,
)
Related
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.
how do i center this? You can see the Code next to the Emulator
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 120,
child: TextFormField(
inputFormatters: [
LengthLimitingTextInputFormatter(3),
],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: const TextStyle(
fontSize: 16,
),
autovalidateMode: AutovalidateMode.disabled,
controller: controller,
cursorColor: Colors.white,
decoration: InputDecoration(
alignLabelWithHint: true,
floatingLabelAlignment: FloatingLabelAlignment.center,
labelText: lableText,
labelStyle: const TextStyle(fontSize: 16)),
),
),
),
I added code Snippet so you can see it better :)
you can do like this
SizedBox(
width: 120,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'In jahren',
),
),)
delete labelText and Use label instead.
give Text to label as child.
wrap label with Center.
TextFormField(
.
.
.
label: Center(
child: Text('In jahren'),
),//center
),//TextFormField
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),
),
),
),
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
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