0

I've copied the same code from file_picker package docs, but it keeps giving me a null value for all file details, here is the code I've copied

FilePickerResult result = await FilePicker.platform.pickFiles();

if(result != null) {
   PlatformFile file = result.files.first;
   
   print(file.name);
   print(file.bytes);
   print(file.size);
   print(file.extension);
   print(file.path);
}

The file name, bytes, size, extension and path are all giving a null value. Anyone know what is the reason for that ? I've tried to upload a pdf, png, jpg, doc and get the same null value for all of them.

1 Answers1

1

I'm using the latest version of this: https://pub.dev/packages/file_picker

  void _openFileExplorer() async {
      File _pickedFile;
      FilePickerResult _filePickerResult;
      setState(() {
        _isLoading = true;
      });
      try {
        _filePickerResult = await FilePicker.platform.pickFiles(
            type: FileType.any,
            allowedExtensions: (_extension?.isNotEmpty ?? false)
                ? _extension?.replaceAll(' ', '')?.split(',')
                : null);
      } on PlatformException catch (e) {
        print("Unsupported operation" + e.toString());
      }
      if (_filePickerResult != null) {
        setState(() {
          _pickedFile = File(_filePickerResult.files.single.path);
        });
      }
      if (!mounted) return;
      {
        Flushbar(
          showProgressIndicator: true,
          progressIndicatorBackgroundColor: Colors.blueGrey,
          title: 'Status:',
          message: 'File loaded: $_pickedFile',
          duration: Duration(seconds: 3),
          backgroundColor: Colors.green,
        )
          ..show(context);
      }
      setState(() {
        _isLoading = false;
      });
    }
krumpli
  • 723
  • 3
  • 15