Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable paste and select all function button from textformfield in flutter

I want to disable all the functionality related to copy, paste and select all on the press of textformfield in the flutter. I have a password field which can take keyboard hint and able to paste data by default but when I perform the operation like calling login service then password field gone wrong.

 TextFormField(
      obscureText: true,
      style: styleText,
      textInputAction: TextInputAction.done,
      controller: _passwordController,
      focusNode: _passwordFocus,
      onFieldSubmitted: (term){
        _passwordFocus.unfocus();
      },
      keyboardType: TextInputType.text,
      validator: validatePassword,
      decoration: InputDecoration(
          focusedBorder: border,
          border: border,
          enabledBorder: border,
          hintStyle: styleText,
          hintText: 'Password'),
      onSaved: (String val) {
        _password = val;
      },
    ),
like image 894
Farhana Naaz Ansari Avatar asked Feb 25 '19 06:02

Farhana Naaz Ansari


People also ask

How to create a textformfield in flutter?

To create a TextFormField in Flutter, Flutter provides a TextFormField () widget. You can style it according to your needs. A simple and without any style underline TextFormField is below. To handle user input in TextFormField, create an object of TextEditingController class.

How to disable the textfield widget?

) 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. Create AlwaysDisabledFocusNode and pass it to the focusNode property of a TextField Widget .

How to take input from the user in flutter?

TextFormField widget is used to take input from the user in flutter. This is a simple and easy user input widget in flutter. We can perform any operation on that user input data using TextFormField. You can use that user input, can send and show that input.

How to add and remove friend text fields in a form?

Create a method in MyFormState, that will generate the list of friend text fields according to the length of friendsList. The last row of the friend text field will have add button and rest all the rows will have remove button with them.


1 Answers

You can use the enableinteractiveSelection : false to Disable the copy/paste.

TextFormField(
          enableInteractiveSelection: false,
          obscureText: true,
          style: styleText,
          textInputAction: TextInputAction.done,
          controller: _passwordController,
          focusNode: _passwordFocus,
          onFieldSubmitted: (term){
            _passwordFocus.unfocus();
          },
          keyboardType: TextInputType.text,
          validator: validatePassword,
          decoration: InputDecoration(
              focusedBorder: border,
              border: border,
              enabledBorder: border,
              hintStyle: styleText,
              hintText: 'Password'),
          onSaved: (String val) {
            _password = val;
          },
        ),
like image 136
Neha Bhardwaj Avatar answered Dec 04 '22 22:12

Neha Bhardwaj