flutterdartontap

Error on method onTap() while calling function


                  TextField(
                    textAlign: TextAlign.center,
                    obscureText: _obscureText,
                    onChanged: (value) {
                      //Do something with the user input.
                      password = value;
                    },
                    style: const TextStyle(color: Colors.black),
                    decoration: const InputDecoration(
                      hintText: 'Enter your Password.',
                      hintStyle: TextStyle(color: Colors.black26),
                      suffix: InkWell(
                        child: Icon(Icons.visibility),
                        onTap: _togglePasswordView,
                        //here is error in onTap
                        
                      ),
                      contentPadding:
                      EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.all(Radius.circular(32.0)),
                      ),
                    

  void _togglePasswordView() {
    setState(() {
      _obscureText = !_obscureText;
    });
  }
}

This is all the code of the page, there is erron in onTap function in suffix. the error message shows that //Invalid constant value// The Image of the error is here Text,


Solution

  • decoration: const InputDecoration

    You defined input decoration as constant but on error it wont be constant. Remove const