skip to Main Content

The following error message occurred.
"The argument type ‘String?’ can’t be assigned to the parameter type ‘String’"

[enter image description here]

img

I don’t understand why this is an error.
If there is anyone who knows the solution, please let me know.

i want to make model and solve that…
thank you…

2

Answers


  1. The value imageFilePath could be null so that means:

    final face = Face(name:faceName,imagePath:imageFilePath!);
    

    or

    You could make the field imageFile in your Face class null-aware:

    class Face {
    
    final String name;
    final String? imagePath;
    
    Face({required this.name,required this.imagePath});
    
    }
    

    then you can easily do this:

    final face = Face(name:faceName,imagePath:imageFilePath);

    There is another option if you don’t want to do the above two suggestions:

    final face = Face(name:faceName,imagePath:imageFilePath ?? '');
    
    Login or Signup to reply.
  2. imageFilePath is a nullabe String, you can do null check and proceed the way did for faceImagePath.

    if(imageFilePath!=null){
       ....
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search