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
Related
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.
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 search some issues on flutter github and stackoverflow to resolve this problem
in below implementation in flutter i can't type Enter to have more line in TextFormField, i think i set correctly keyboardType and maxLines, but my keyboard on phone doesn't have enter key and that's next
TextFormField(
textAlign: TextAlign.start,
keyboardType: TextInputType.multiline,
maxLines: 7,
style: Theme.of(context).textTheme.caption.copyWith(
color: Colors.black,
),
textInputAction: TextInputAction.next,
),
Remove textInputAction: TextInputAction.next
TextFormField(
textAlign: TextAlign.start,
keyboardType: TextInputType.multiline,
maxLines: 7,
style: Theme.of(context).textTheme.caption.copyWith(
color: Colors.black,
),
//textInputAction: TextInputAction.next,
);
or as #Siddharth Patankar commented set textInputAction: TextInputAction.newline
Here is the code. I want to remove the black underline just below text, and currently the TextField is in edit mode:
TextField(
autofocus: true,
decoration: InputDecoration.collapsed(
hintText: "Search",
border: InputBorder.none,
),
maxLines: 1,
)
Try to give a TextStyle to your TextField widget. Your TextField is getting your default Theme's TextStyle.
TextField(
autofocus: true,
style: TextStyle(color: Colors.white, fontSize: 30),
decoration: InputDecoration.collapsed(
hintText: "Search",
border: InputBorder.none,
),
maxLines: 1,
)
In TextField widgets source code it states:
/// If null, defaults to the `subhead` text style from the current [Theme].
final TextStyle style;
You should use TextDecoration.none in decoration property.
Text(
'your txt',
style: TextStyle( decoration: TextDecoration.none),
)
I suspect it's something to do with the predictive text. The underlines disappear when you press the space bar to end the word you're typing; they then start appearing again when you start typing the next word. As suggested here, try setting TextInputType.visiblePassword; - this worked for me.
just code ...
TextFormField(
decoration: InputDecoration(
hintText: 'comment..',
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
contentPadding: EdgeInsetsDirectional.only(start: 10.0),
),
)
style:TextStyle(
decorationThickness: 0)
As stated in https://stackoverflow.com/a/57499189/445887
This is an accessibility feature (if you still see an underline after disabling it in TextStyle) from the Android keyboard.
Then input text is always underlined while typing use:
autocorrect: false,
enableSuggestions: false,
https://stackoverflow.com/a/69921656/10932271
Provide the following code inside the TextField widget and change the color according to the background color of a TextField. If the background is white provide white color which will make the underline invisible.
style: TextStyle(
fontSize: 16,
letterSpacing: 1,
decoration: TextDecoration.none,
decorationStyle: TextDecorationStyle.dotted,
decorationColor: Colors.white),
You have to add a "decoration:TextDecoration.none", like this:
Text(
"Don't forget",
style: TextStyle(
decoration: TextDecoration.none
)
)
#Immortal Dude is right that this is not the problem of textfield. Because when you click somewhere else after typing in the textfield, the underline automatically remove from the text.
You just need to set the keyboard type:
keyboardType: TextInputType.visiblePassword,
I have a TextField like this, where the input text and the hint text are sized differently.
TextField(
style: Theme.of(context).textTheme.subhead.copyWith(
fontSize: 70.0,
),
decoration: InputDecoration(
hintText: 'Enter a number',
hideDivider: true,
hintStyle: TextStyle(
color: Colors.grey[500],
fontSize: 25.0,
),
),
);
While the user input text is centered in my parent container, the hintText is not (top has more space than the bottom). Is there a way to vertically center the hint text as well?
The reason the hint text is not the same size as the input text is that it takes up more space than the green Container has, so it looks like Enter a nu..., which isn't very user friendly. (So alternatively, is there a way to have a newline in the hintText?)
I see this is over 2 years old but in case others run into this problem:
InputDecoration has the property contentPadding.
TextField(
decoration: InputDecoration(
hintText: 'Hint Text',
contentPadding: EdgeInsets.all(10.0),
),
);
Add textAlignVertical: TextAlignVertical.center, in your TextField.
Note: make sure you are not modifying it with other Containers or anything else & if you do then check those widgets as well.
TextField(
textAlignVertical: TextAlignVertical.center,
),
new TextField(
decoration: new InputDecoration(
hintText: 'your hint',
),
textAlign: TextAlign.center,
)
textAlign: TextAlign.center will make your hint appear in the center.
Below is the solution for your problem:
Container(
color: Colors.red,
width: 1000,
height: 500,
alignment: Alignment.center,
child: TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
style: new TextStyle(fontSize: 20),
decoration: InputDecoration(
hintText: 'Email', hintStyle: TextStyle(color: Color(0xff777777))),
),
)