I have a TextFormField when the user clicks on it there is a huge space in between comes. As keyboard opening adds padding.
This is my widget tree
Code
TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
maxLines: 1,
style: TextStyle(color: text_color, fontSize: 14),
decoration: InputDecoration(
fillColor: appBackground_color,
filled: true,
focusColor: text_color,
contentPadding: EdgeInsets.all(12),
disabledBorder: InputBorder.none,
labelText: StringClass.ENTER_NAME),
),
),
Related
I have Text field which will take a long message from the user and I set expands to True
the problem is the hint text is not at the beginning of the the line, How do I change its position ?
SizedBox(
height: 150,
child: CustomTextField(
enabledRadius: 7,
focusedRadius: 7,
expands: true,
hintText: 'message',
controller: messageController,
textInputType: TextInputType.multiline,
),
),
Thanks everyone, I figured it out by using
textAlignVertical: TextAlignVertical(y: -1),
You can use `textAlign:TextAlign.start` to align the hint
Here see the full code:
SizedBox(
height: 150,
child: CustomTextField(
enabledRadius: 7,
focusedRadius: 7,
expands: true,
maxLines: null,
textAlign: TextAlign.start,
hintText: 'message',
controller: messageController,
textInputType: TextInputType.multiline,
),
),
You can customise TextFormField by using these properties.
textAlign: TextAlign.left,
decoration: const InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: '0',
counterText: '',
hintStyle: TextStyle(
color: greyPlaceholderColor,
fontSize: fontSize40,
fontWeight: FontWeight.w700)),
I tried using stack widget but it's not work.
I see some references from native Android, and there's no error like this.
source code
const Expanded(
child: Scrollbar(
child: TextField(
decoration: InputDecoration(
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
hintText: 'Write a message...',
),
maxLines: 6,
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
minLines: 1,
),
),
),
I want to get rid of the letters going up when I hit enter in a text field. What should I do?
It's part of the code.
Container(
child: TextField(
textAlign: TextAlign.center,
autofocus: true,
// controller: myController,
onChanged: (value) {
// print('$value');
setState(() {
mainText = value;
});
},
keyboardType: TextInputType.multiline,
minLines: 1,
maxLines: 10,
decoration: InputDecoration(
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
hintText: "짧은 글귀를 집필해주세요",
hintStyle:
TextStyle(fontSize: 14, color: Colors.black),
),
),
)
As per your hint text you just want short text and you can achieve by integrating with only single line textfield
Container(
child: TextField(
textAlign: TextAlign.center,
autofocus: true,
// controller: myController,
onChanged: (value) {
setState(() {
mainText = value;
});
},
keyboardType: TextInputType.text, // this is change
textInputAction: TextInputAction.done, // this is change
decoration: InputDecoration(
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
hintText: "짧은 글귀를 집필해주세요",
hintStyle: TextStyle(fontSize: 14, color: Colors.black),
),
),
)
for multiline text:
keyboardType: TextInputType.multiline,
maxLines: 5,
textInputAction: TextInputAction.newline,
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,
),
)),
],
),
I want to put some padding from top, label is coming out from Textfield when entering text in TextFormField,
I tried content padding , but still not working.
here is my code
#override
Widget build(BuildContext context) => TextFormField(
controller: TextEditingController(),
style: Theme.of(context).textTheme.subtitle2,
decoration: InputDecoration(
fillColor: Theme.of(context).disabledColor,
border: OutlineInputBorder(
borderSide:
BorderSide.none,
borderRadius: BorderRadius.circular(BorderSize.input),
),
contentPadding:
EdgeInsets.all( PaddingSize.inputHorizontal),
filled: true,
isDense: true,
labelText: hint),
onSaved: onSaved,
validator: _exists);
}
It seems to be a problem with the border. If you don't need them, just remove and try.
TextFormField(
controller: TextEditingController(),
style: Theme.of(context).textTheme.subtitle2,
decoration: InputDecoration(
fillColor: Theme.of(context).disabledColor,
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding:
EdgeInsets.all( PaddingSize.inputHorizontal),
filled: true,
isDense: true,
labelText: hint),
onSaved: onSaved,
validator: _exists);
Let me know if this is expected.
EDIT :
Disable all the borders as above.