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,
),
),
CodePudding user response:
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.
},
CodePudding user response:
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