Home > Software design >  PlatformFile selectedFile Type: PlatformFile The argument type 'String?' can't be ass
PlatformFile selectedFile Type: PlatformFile The argument type 'String?' can't be ass

Time:03-13

So i was following along a curse on youtube, but he made a list like this 'List selectedFiles = List();' and it gave me an error so i did it like this 'List selectedFiles = [];' but now it gives me an error and idk if it is because of that

enter image description here

enter image description here

CodePudding user response:

Use null check operator on selectedFile.path as it could be null at run time.

CodePudding user response:

You need to cast the selectedFile null variable to a non-null form of it.

You do that by adding the exclamation mark(!) as a post fix to the null variable.

Solution:

Change this:

File file = File(selectedFile.path)

to this;

File file = File(selectedFile!.path)

Note:

This could fail at runtime if selectedFile is actually null.

You can mitigate this issue by checking if the value is null like this:

if (selectedFile != null) { 
  File file = File(selectedFile!.path)
  //Other operations
} else {
  print('selectedFile is null');
}
  • Related