Samreaksa Ros

Web Developer - iOS Developer

Toggle Password Text Visibility – Flutter

Widget _showPasswordInput() {
    return Padding(
              padding: EdgeInsets.only(top: 20.0),
              child: TextFormField(
                onSaved: (val) => _password = val,
                obscureText: _obscureText,
                validator: (val) => val.length < 8 ? 'Password too short' : null,
                decoration: InputDecoration(
                  suffixIcon: GestureDetector(
                    onTap: () {
                      setState(() {
                       _obscureText = !_obscureText; 
                      });
                    },
                    child: Icon(
                      _obscureText ? Icons.visibility : Icons.visibility_off
                    ),
                  ),
                  
                  border: OutlineInputBorder(),
                  labelText: 'Password',
                  hintText: 'Enter password, min length 6',
                  icon: Icon(Icons.lock, color: Colors.grey))
                )
            );
  }