Icon Button relesae tab event in Flutter

364 views Asked by At

Am doing a TextForm Button with Suffex icoon button , I inteneded to show password only while am pressing the button and when I release it it should go back to password format. I could do it only with onyl press.

this is the code

TextFormField(
                  obscuringCharacter: '#',
                  obscureText: passwordVisible,
                  controller: password,
                  decoration: InputDecoration(
                    suffixIcon: IconButton(
                      icon: const Icon(Icons.remove_red_eye),
                      onPressed: () {
                        setState(() {
                          passwordVisible = !passwordVisible;
                        });
                      },
                    ),
1

There are 1 answers

0
Bareq Raad On

I just solved it by adding longpress event

TextFormField(
                  obscuringCharacter: '#',
                  obscureText: passwordVisible,
                  controller: password,
                  decoration: InputDecoration(
                    suffixIcon: GestureDetector(
                      child: IconButton(
                        icon: const Icon(Icons.remove_red_eye),
                        onPressed: () {
                        },
                      ),
                      onLongPressEnd: (LongPressEndDetails Details){
                        setState(() {
                          passwordVisible = true;
                        });
                      },
                      onLongPress: () {
                        setState(() {
                          passwordVisible = false;
                        });
                      },

                    ),