flutter 'file picker ' error . the getter 'name' is not defined

This is a screenshot of my error screenshot of error
Please tell me why i am getting this error because according to documentation of file_picker file.name should return name of the file but instead i am getting getter name is not defined .

>Solution :

First, I think it would be better if you copy paste the code, otherwise people can’t reproduce the problem.

Anyway I think the problem is that you’re confusing PlatformFile with File (from the dart:io package). The first one has the attribute name, the second doesn’t, and you are trying to retrieve that attribute from an element of a List.

If you want the name of the files you should do

List<PlatformFile>? list_result;

if(result != null) {
    List<PlatformFile> files = result.files;
    setState((){
        list_result = files;
    });
}

Leave a Reply