I want the value of textfield when user prints enter - flutter

I am a beginner in flutter, I was working with the textfield widget. I want the value of textfield when user click enter or when the value is completed. Thanks for the help in advance.
TextField(
cursorColor: primaryColor,
decoration: InputDecoration(
icon: Icon(
Icons.search,
color: primaryColor,
),
hintText: 'Search for your favourite',
border: InputBorder.none,
),
),

To get the text field value once it is completed, you can use the text field onSubmitted function. It provides you with the value once the user submits it. Here is the line of code you need to add.
TextField(
cursorColor: primaryColor,
decoration: InputDecoration(
icon: Icon(
Icons.search,
color: primaryColor,
),
hintText: 'Search for your favourite',
border: InputBorder.none,
),
onSubmitted: (value) {
print(value); // This will print the value submitted by the user. You can add your function inside this.
},

You can use onChanged to print it out.
TextField(
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(hintText: 'Eenter your email')),
if you would like to use an advanced validator to check input value.
Please refer to this page flutter-how-to-change-border-of-text-form-field-on-error

Related

how add text and icon inside TextFormField in flutter

i want to make the text and icon inside TextFormField
this is my code
enter image description here
_FormField() {
return TextFormField(
validator: (value) {
if (value!.isEmpty) {
print("test");
}
},
decoration: InputDecoration(
fillColor: kPrimaryLightColor,
filled: true,
focusColor: kPrimaryLightColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide.none),
//hintText: 'Email'
//hintStyle: TextStyle(color: Colors.black38),
labelText: 'Email',
labelStyle: TextStyle(color: kPrimaryColor),
//icon: Icon(Icons.email),
icon: Icon(Icons.email_outlined),
),
);
}
i want it like that
enter image description here
You can use prefixIcon and suffixIcon of inputDecoration to add icons inside the field. If you want the field label only within the field and not as a label above it, specify only hintText and leave out LabelText. Check the following code, you can wrap the icons inside a Padding if you need more space.
TextFormField(
validator: (value) {
if (value!.isEmpty) {
print("test");
}
},
decoration: InputDecoration(
prefixIcon: Icon(Icons.email_outlined),
fillColor: Colors.grey,
filled: true,
focusColor: Colors.blue,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide.none),
hintText: 'Email',
suffixIcon: Icon(Icons.email_outlined),
),
)
your can use prefixIcon and suffixIcon which takes widget. In which you can give Icon to the prefixIcon and to the suffixIcon you can give IconButton in which you can give the logic to hide/show password. To implement the logic declare a boolean variable which is used for if the password is to be shown or hidden. the logic must be like this.
bool showPassword=false;
_FormField() {
return TextFormField(
obscureText: !showPassword,
validator: (value) {
if (value!.isEmpty) {
print("test");
}
},
decoration: InputDecoration(
suffixIcon:IconButton(icon:showPassword?Icon(Icons.lock):Icon(Icons.lock_open),
onPressed:(){
setState(() {
showPassword=!showPassword;
});
}
)
),
);
}
The code is not formatted well sorry for that I write it manual here 🙏

Not able to disable keyboard appearing automatically

The moment I come on this page the keyboard appears automatically, I want to disable that.When someone press on the enter email.I want keyboard to come at that time only.
I have tried every thing nothing seems to work.Can someone please help me out
Form(
child: Column(
children: [
TextFormField(
// focusNode: fEmail,
onFieldSubmitted: (term) {
// fEmail!.unfocus();
FocusScope.of(context).unfocus();
// FocusScope.of(context).requestFocus(fPass);
},
textInputAction: TextInputAction.next,
autofocus: true,
style:TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Email',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
onFieldSubmitted: (term) {
fPass!.unfocus();
FocusScope.of(context).unfocus();
// FocusScope.of(context).requestFocus(fButton);
},
focusNode: fPass,
textInputAction: TextInputAction.next,
autofocus: true,
style:TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your PassWord',
hintStyle: TextStyle(color: Colors.white60),
),
),
],
),
),
Remove autofocus: true, from your code or set it to autofocus: false,
Refer Focus and text fields here
Refer autofocus property here
You can use focus node to control the behaviour.
If you put autofocus=true in your code it will automatically focus on the topmost textfield widget in the current tree.
put autofocus = false or remove the parameter as it is false by default.
You can use focus Node to control the behaviour.
if you put autofocus: true if your code. this line will automatically focus on the top most Textfield widget.
put autofocus: false in our code it will be disable your keyboard which is opening automatically in the text filed.
Refer Focus and text fields: here
Refer autofocus property: here

flutter TextField suffixText onclick event or any ontap method how to use

use in TextField and decoration in suffixText show text but need suffixText click event
TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
hintText: 'Password',
hintStyle: TextStyle(color: Colors.white),
contentPadding: const EdgeInsets.all(24),
prefixIcon: Icon(Icons.lock, color: Colors.white),
suffixText: 'forget?'.toUpperCase(),
),
),
There is also an suffix property available in TextField. You can use it in place of suffixText and provide it either an GestureDetector or InkWell for the onTap method and give their child the Text Widget you are providing to suffixText.
suffix:GestureDetector(
onTap:(){},
child:Text("Your Text"),
),

Create something like InputDecoration and OutlineInputBorder for Text Widget

I would like to implement a Text Widget whose label works in a similar way to the TextField below. (I don't expect I can input a value to the Text Widget. The Text Widget will be only for showing a text.) Could anyone teach me this?
If the value is '' (empty string), then show "Output" in the box.
If the value is not empty, then show "Output" on the border.
TextField sample
Without value:
With value:
TextField(
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.display1,
decoration: InputDecoration(
labelText: 'Input',
labelStyle: Theme.of(context).textTheme.display1,
errorText: _hasInputError ? 'Invalid number entered' : null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
),
),
),
TextFormField(
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.bodyText1,
decoration: InputDecoration(
labelText: 'Input',
hintText: "Input",
labelStyle: Theme.of(context).textTheme.bodyText1,
errorText: _hasInputError ? 'Invalid number entered' : null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
),
),
),

Flutter TextFormField: Align text description on left of entry field

Good day, I am creating TextFormFields in Flutter and I am getting a bit frustrated that I can't have Text on the left of the entry input that STAYS there.
hintText disappears when you enter the field.
prefixText only appears after you enter the field.
prefixIcon does exactly what I want, but I want Text instead of an icon.
The above image uses prefixIcon and hintText.
Does anyone have a suggestion on how to replace the icon I currently have with permanent Text instead, please? Thank you for any and all assistance.
Try using the prefixText property in decoration.
TextField(
controller: _textController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Enter a valid ZIP-Code',
errorText: _hasInputError ? "ZIP-Code is too short" : null,
counterText: _textController.text.length.toString(),
helperText: "ZIP-Code of shipping destination",
labelText: "ZIP-Code",
prefixText: "DE - ",
suffixIcon: Icon(Icons.airport_shuttle),
),
),
Refer this link
I think you cannot use prefixIcon when using decoration.
prefixIcon takes in a Widget type so you can pass a Widget into it if you want
TextFormField(
controller: _passwordController,
decoration: InputDecoration(
hintText: "Password",
prefixIcon: CircleAvatar(
backgroundImage: NetworkImage(kDefaultProfilePicture),
) // You can replace this with a Text("") widget,
suffixIcon: IconButton(
icon: Icon(Icons.visibility),
onPressed: () {},
),
),
),
I used prefixIcon with an UnconstrainedBox:
TextFormField(
decoration: InputDecoration(
prefixIcon: UnconstrainedBox(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text("Date:")
)
)
)
)