Home > OS >  File path error when creating model (String error)
File path error when creating model (String error)

Time:12-09

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...

CodePudding user response:

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 ?? '');

CodePudding user response:

imageFilePath is a nullabe String, you can do null check and proceed the way did for faceImagePath.

if(imageFilePath!=null){
   ....
}
  • Related