When I select all the text in Textfield there's a line between each lines of text. This line appears when I increase the Textfield fontSize.
Behavior
Expected behavior
Edit
Below is my Textfield code snippet. I made this as re-usable.
TextField(
onTap: onTap,
controller: controller,
focusNode: focusNode,
obscureText: obscureText ?? false,
autofocus: autofocus ?? false,
onChanged: onChanged,
onEditingComplete: onEditingComplete,
onSubmitted: onSubmitted,
scrollPhysics: const BouncingScrollPhysics(),
maxLines: maxLines,
minLines: minLines,
textCapitalization: TextCapitalization.sentences,
textInputAction: textInputAction,
keyboardType: TextInputType.multiline,
selectionWidthStyle: BoxWidthStyle.max,
readOnly: readOnly!,
selectionHeightStyle: BoxHeightStyle.strut,
maxLengthEnforcement: MaxLengthEnforcement.enforced,
style: TextStyle(
fontSize: fontSize,
fontWeight: fontWeight ?? FontWeight.normal,
color: color ?? Theme.of(context).primaryColor,
),
enableInteractiveSelection: true,
decoration: decoration ??
InputDecoration(
isDense: isDense,
border: InputBorder.none,
icon: iconData ?? widgetIcon,
suffix: suffix,
hintText: hintText,
hintStyle: TextStyle(
fontSize: fontSize ?? hintFontSize,
fontWeight: fontWeight ?? FontWeight.normal,
),
),
);
This is a font specific problem with your chosen font size.
For example if you change text style to this:
TextStyle(
fontSize: fontSize,
fontWeight: fontWeight ?? FontWeight.normal,
height: 1.0,
color: color ?? Theme.of(context).primaryColor,
),
You will no longer see the spaces, check the description on height for more details.
Related
I have list of tasks and below that I have TextField, now when the multiple tasks added then I need to show TextField just above the keyboard.
How can I achieve this?
Thanks in Advance!
Small piece of code :
TextFormField(
scrollPadding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom - 160), // this line not work for me.
cursorColor: Colors.black,
toolbarOptions: ToolbarOptions(copy: true, cut: true, paste: true, selectAll: true),
showCursor: MediaQuery.of(context).viewInsets.bottom != 0 ? true : false,
style: new TextStyle(
fontSize: 15.0,
fontFamily: "Roboto",
fontWeight: FontWeight.w400,
color: darkGreyColor,
),
controller: _textFieldControllerSubTaskAdd,
focusNode: focusNodeSubTask,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
onChanged: (text) {
},
),
I have added the text that is displayed in the TextFormField. I need to change the text size of not everything, but only KWh, make it smaller + can the € and KWh values be made static so that they cannot be changed?
code
TextFormField(
keyboardType: TextInputType.number,
controller: _priceController
..text = '€' + widget.price.toStringAsFixed(2) + ' KWh',
style: widget.textStyle,
textAlign: TextAlign.center,
decoration: const InputDecoration(
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
),
),
This is why Suffix and Prefix are provided in InputDecoration.
To use them for your desired output, do as:
TextFormField(
keyboardType: TextInputType.number,
controller: _priceController
..text = widget.price.toStringAsFixed(2),
style: widget.textStyle,
textAlign: TextAlign.center,
decoration: const InputDecoration(
prefix: Text('€',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
suffix: Text('KWh',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
),
),
You can change the color, fontSize, fontWeight or any such TextStyle property by using widgets for Suffix and Prefix. Prefix and Suffix stay static and can't be changed/Edited by the user.
Output:
Do Remember, Suffix is placed at the end of the TextFormField, so, you've to adjust the its width according to that.
Else, it will look like this with a full width TextFormField:
I am customizing flutter ecommerce mobile app from codecanyon.
I want to hide the Pincode box. There are two ways to get the value in the Pincode box either manually or from google mab.
I want the value to be selected only from google mab.
how can I hide the text box?
setPincode() {
return TextFormField(
keyboardType: TextInputType.number,
controller: pincodeC,
style: Theme.of(context)
.textTheme
.subtitle2
.copyWith(color: colors.fontColor),
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
onSaved: (String value) {
pincode = value;
},
validator: (val) => validatePincode(
val,
getTranslated(context, 'PIN_REQUIRED'),
),
decoration: InputDecoration(
hintText: getTranslated(context, 'PINCODEHINT_LBL'),
isDense: true,
),
);
}
you can do that with the visibility widget, it gets a bool value that indicates if the child can be visible or not, i believe this widget solves your problem.
exemple:
return Visibility(
visible: controller.cards.isNotEmpty,
replacement: const Text(
"Ops! Você ainda não tem eventos para esta data",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.grey,
),
),
TextInputAction.newline does not work on custom keyboards, only on the Google keyboard, when I press the Enter key on custom keyboards, nothing happens.
TextField(
focusNode: focusNode,
textInputAction: TextInputAction.newline,
style: Theme.of(context)
.textTheme
.subtitle1!
.copyWith(fontSize: config.s17),
onChanged: (text) {
feedbackBloc.add(MessageChangedEvent(text));
},
keyboardType: TextInputType.multiline,
maxLines: null,
maxLength: 2000,
buildCounter: (
context, {
required currentLength,
required isFocused,
maxLength,
}) =>
null,
decoration: InputDecoration.collapsed(
hintText: tr('settings.how'),
hintStyle: TextStyle(
color: grayTextColor,
fontSize: config.s17,
fontWeight: FontWeight.w400,
),
),
),
I'm using a textfield widget:
TextField(
controller: _taskNamecontroller,
focusNode: _focus,
textInputAction: TextInputAction.done,
maxLines: null,
decoration: InputDecoration(
border: InputBorder.none,
hintText: SC.current.taskHeaderTaskName),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
height: 1.25),
),
and when adding this emoji 1️⃣ from the keyboard, it renders very strangely, it shows the 1 followed by a weird symbol:
Why is Flutter failing to render this emoji appropriately?
use GoogleFonts.notoColorEmojiCompat() for style