How does one underline for each character in Flutter? I want to do phone verification and want each line to hold a single character but don't know how to do it (or if it's even possible) with a single TextForm.
Example:
This is a rephrased version of this question: Connecting multiple text fields to act like a single field in Flutter
Flutter package that handles this: https://pub.dev/packages/pin_code_fields
Use this :
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
Must Add this In your ThemeData:
ThemeData(
primarySwatch: Colors.red,
accentColor: Colors.amber,
For Your Case You Can Dow that
Row(
children<>[
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
TextField(
obscureText: true,
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
maxLength: 1,
),
]
)
For Layout Fixing use Exapand()
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 code like this
Stack(
children: [
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
),
Positioned(
bottom: 14,
left: 0,
child: Text("Rp"),
),
],
),
I know I can set the text in the center using TextAlign.center, but now I want to make the text inside textfield at the start + around 24 pt from start
I can't use TextAlign.start since it will overlap the 'Rp' text.
how to do that?
Use Prefix or Suffix for the "Rp" text:
TextFormField(
decoration: InputDecoration(
prefix: ...,
suffix: ...,)
Then you can use textAlign
Try below code hope its helpful to you you can use prefix propery inside Inputdecoration of TextFormField here and InputDecoration here
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(
prefix: Text('Rp'),
),
),
Your result screen->
TextFormField(
decoration: InputDecoration(
prefixText: 'Rp',
),
),
I try to make a TextField with keyboardType: TextInputType.visiblePassword to disable the predictive text but with that I can't go to a new line because it's a submit button. I try to add textInputAction: TextInputAction.newline but don't work too.
My TextField:
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100])
))));
You just add below parameter to disable predicting text.
enableSuggestions: false,
autocorrect: false,
But to enable multiline, you need to change 'keyboardType' to 'TextInputType.multiline'.
TextField(
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
decoration: InputDecoration(fillColor: Colors.grey[100]))
if next line button show inside keyboard, so use only two line
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
Change TextInputAction.newline to TextInputAction.next
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions:
const ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(
fillColor: Colors.grey[100],
),
),
I add my textfield in a RawKeyboardListener and when user press "Enter" it's detect automatically.
RawKeyboardListener(
focusNode: FocusNode(),
onKey: (event) {
if(event.isKeyPressed(LogicalKeyboardKey.enter)) {
int cursorPos = textEditor.selection.base.offset;
textEditor.text = textDebut + '\n' + textFin;
textEditor.selection = TextSelection.fromPosition(TextPosition(offset: cursorPos + 1));}},
child:TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100]),
onChanged: (String text) {print(text);}))
add this line : textInputAction: TextInputAction.newline,
remove this line : keyboardType: TextInputType.text,
TextField(
//keyboardType: TextInputType.text,
textInputAction: TextInputAction.newline,
maxLines: 30,
decoration: InputDecoration(
border: InputBorder.none,
labelStyle: greyTextStyle400,
hintStyle: greyTextStyle400,
hintText: "Message...",
),
),
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
I want to add asteric sign in InputDecoration labelText and change color(like red) of it so that user understand easily this field is required.
TextField(
autofocus: true,
controller: _nameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name *",
))
Expected result like this image
Sample Image
You can use the Rich Text Widget like this
RichText getRequiredLabel(String fieldName) {
return RichText(
text: TextSpan(
style: TextStyle(color: Colors.black),
text: fieldName,
children: [
TextSpan(text: '*', style: TextStyle(color: Colors.red))
]));
}
You can use label arguments inside InputDecoration parameters. This work both widgets TextField or TextFormField
TextField(
decoration: InputDecoration(
label: Row(
children: [
const Text('*', style: TextStyle(color: Colors.red)),
Padding(
padding: EdgeInsets.all(3.0),
),
Text("Name")
],
),
),
controller: _nameCtrlr,
autofocus: true,
keyboardType: TextInputType.text,
);
Yes, man you can do that.
TextField(
autofocus: true,
controller: _nameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name \*",
))
"\" sign will help compiler to distinguish between asterisk sign(*) from multiplication.