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
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 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,
)
I want to make the hint text in TextFormField disappear when the field focused. But the hint text won't disappear until I insert a character in the field. I did the following. How can I make the hint text disappear when the field focused? Thanks!
Container buildTextField(bool isObscure, TextEditingController textEditingController, String hintText, bool onlyNumber) {
return Container(
width: double.infinity,
height: 60,
color: MyColors.primary,
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.only(left: 15, right: 10),
child: TextFormField(
textAlign: TextAlign.center,
keyboardType: onlyNumber ? TextInputType.number : TextInputType.text,
decoration: InputDecoration(
hintText: hintText,
hintStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
border: InputBorder.none,
),
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none,
fontWeight: FontWeight.w600,
),
obscureText: isObscure,
controller: textEditingController,
),
),
);
}
You probably have to add a listener to listen to focus changes:
FocusNode myFocusNode = FocusNode();
myFocusNode.addListener( () {
setState((){});
}
And then, inside your InputDecoration you update the value:
hintText: myFocusNode.hasFocus ? hintText : ''
Use labelText instead,
TextFormField(
controller: fullNameController,
validator: (value) {
if (value.trim().isEmpty) {
return Lang.enterFullName;
}
return null;
},
decoration: InputDecoration(
labelText: Lang.fullName,
prefixIcon: Icon(Icons.person),
),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
),