TextField clear set get the value using null safety with getX

in this flutter tutorial we discuss about flutter textfield clear set and get the value using null safety with getx

TextField clear set get the value using null safety with getX

TextField clear set get the value using null safety with getX

TextField widget:

  • TextField widget of flutter has inbuild flutter widget.
  • TextFormField, which integrates with the Form widget.
  • A Form ancestor is not required. The Form simply makes it easier to save, reset, or validate multiple fields at once.
  • TextField widget used to user input the value.

final _formKey = GlobalKey();
Form(key: _formKey, autovalidate: false)

Clear textfield value in flutter using null safety?

Null safety TextField using clear the value::
final TextEditingController? emailController = TextEditingController();
emailController!.clear(); //Clear textField value

Without null safety using TextField clear the value:

final TextEditingController emailController = TextEditingController();
emailController.clear(); //Clear textField value

Set the value using GetX in flutter:

For example: This is used to profile edit screen.

late TextEditingController? emailController;
 void onInit() {
   emailController = TextEditingController(text: '[email protected]');

TextEditingController is used various operation clear, set the value and get value.

TextFormField property in flutter.

1) onTap:

2) readOnly: Use to read or write the permission apply the textfield.

3) initialValue:

4) autovalidateMode: Use the auto validate property if you want to validate on changed.

5) controller: Use to get, set and clear value.

6) validator: Use to validation.

7) onChanged: Use to search from the ListView.

8) minLines: These properties are used to define the minimum number of lines. If this is null (default), text container starts with enough vertical space for one line and grows to accommodate additional lines as they are entered.

9) maxLines: By default, TextField shows as a single line. But we can specify the maximum number of lines to be supported via the maxLines property. This will not limit the number of lines you can add, it only shows the specified number of lines at a time. If you want to expand the field based on the amount of input text, you can set null to the maxLines property

10) onSaved: save() function. Save function will allow you just to save all the value at once if you want to save the values on submission.
For example: onSaved: (value) { phoneNo = value }

11) enabled: TextField and TextFormField both have an argument called enabled. You can control it using a boolean variable. enabled=true means it will act as an editing text field whereas enabled=false will Disable the TextField Widget.

12) obscureText: Converting a normal text field to a password field. By setting the obscureText property to true you can convert a plain text field to a password field, which masks the input values.

13) inpitFormatters: Restricting and allowing input values. For example: inputFormatters: [FilteringTextInputFormatter.deny(RegExp(“[0-9]+”))]

  • Allowing specific characters, which can be set using FilteringTextInputFormatter.allow()
  • Denying specific characters, which can be set using FilteringTextInputFormatter.deny()

14) decoration: InputDecoration(filled, hintStyle, hintText, labelText, fillColor, border, errorText, errorStyle, focusedErrorBorder, errorBorder): used to styling a text field, border, labelText etc.

15) keyboardType: You may have seen applications show different keyboard layouts for different input types, like number pads for phone numbers or an “@” symbol for emails. This can be done in Flutter via the keyboardType property. It accepts TextInputType with multiple options like number, date, phone, name, and email address. For example: TextInputType.number, TextInputType.email

16) maxLength: maxLength property accepts integer values to specify the maximum number of characters accepted by the particular field.

TextFormField validation in flutter using null safety with getx:

static const String cantBeEmpty = "can't be empty";
static const String emailCantBeEmpty = 'Email $cantBeEmpty';
static const String enterValidEmail = 'Enter the valid email';
static String? validateEmail(String? v) {
  if (v!.isEmpty) {
    return ValueString.emailCantBeEmpty;
  } else if (!GetUtils.isEmail(v)) {
    return ValueString.enterValidEmail;
  } else {
    return null;

String? emailValidation(String? value) => validateEmail(value);

check validation email in flutter:
validator: emailValidation

TextFormField enter the value get and set?
final _email = "".obs;
get emailGet => this._email.value;
set emailSet(value) => this._email.value = value;

//Store value from TextField
void setEmail(String? value) => emailSet = value;
validator: emailValidation

TextFomField enter the value get and set?

final _email = "".obs;
get emailGet => this._email.value;
set emailSet(value) => this._email.value = value;

//Store TextField value
void setEmail(String? value) => emailSet = value;

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in