How to show/hide password in TextFormField?

前端 未结 9 1267
故里飘歌
故里飘歌 2021-02-01 00:54

Currently I have my password TextFormField like this:

TextFormField(
  decoration: const InputDecoration(
         


        
9条回答
  •  爱一瞬间的悲伤
    2021-02-01 00:58

    Well I personally like to keep the passwords hidden all the time and seen when you want to see them, so this is the approach I use to hide/unhide passwords,Incase you want the password to be visible when the touch is In contact with the hide icon, and hidden as soon as you remove the contact then this is for you

    //make it invisible globally
      bool invisible = true;
    
    //wrap your toggle icon in Gesture Detector
      GestureDetector(
       onTapDown: inContact,//call this method when incontact
       onTapUp: outContact,//call this method when contact with screen is removed
       child: Icon(
       Icons.remove_red_eye,
       color: colorButton,
       ),
      ),
    
      void inContact(TapDownDetails details) {
        setState(() {
          invisible = false;
        });
      }
    
      void outContact(TapUpDetails details) {
        setState(() {
          invisible=true;
        });
      }
    

    I have also published this as a package here https://pub.dev/packages/passwordfield

    The output of the above code

提交回复
热议问题