Home > Net >  how to solve Invalid constant value.dart erreur
how to solve Invalid constant value.dart erreur

Time:05-11

i wanna show a message i have specific condition else another one so i have choose the visibility widget . my problem is that it shows error on !isValidEmail . isValidEmail is a bool variable

Invalid constant value.dart(invalid_constant)

 Visibility(
            visible: (!isValidEmail && isDouleEmail),
            child: const Padding(
              padding: EdgeInsets.only(left: 8.0),
              child: !isValidEmail 
                  ? Text(
                      "Mail incorrect",
                      style: TextStyle(color: Colors.red, fontSize: 20),
                    )
                  : Text(
                      " not found found ",
                      style: TextStyle(color: Colors.red, fontSize: 20),
                    ),
            ),
          ),

CodePudding user response:

you cant use const when you pass variable in

use it like this (remove the const in Padding widget)

 Visibility(
            visible: (!isValidEmail && isDouleEmail),
            child: Padding(
              padding: EdgeInsets.only(left: 8.0),
              child: !isValidEmail 
                  ? Text(
                      "Mail incorrect",
                      style: TextStyle(color: Colors.red, fontSize: 20),
                    )
                  : Text(
                      " not found found ",
                      style: TextStyle(color: Colors.red, fontSize: 20),
                    ),
            ),
          ),

CodePudding user response:

Your Padding widget is not a constant because its child is changing according to isValidEmail value. However, you declare it as a constant.

Remove const in child: const Padding(

  • Related