flutterdartfilepicker

2 positional argument(s) expected, but 1 found. and The argument type 'String?' can't be assigned to the parameter type 'List<Object>'


I have been able to open my files using the file picker package but I am to save the result path to the pdfFile variable.

This is the variable

File? pdfFile;

I am getting the error from the code below

onPressed: () async {
          FilePickerResult? result = await FilePicker.platform.pickFiles(
            type: FileType.custom,
            allowMultiple: false,
          ); //allowedExtensions: ['pdf', 'doc']);
          if (result == null) return;
          final path = result.files.single.path;
          setState(() {
            pdfFile = File(path); //2 positional argument(s) expected, but 1 found. and The argument type 'String?' can't be assigned to the parameter type 'List<Object>'.
          });
        }

Solution

  • Make sure the import section is correct.

    import 'dart:io';   // for File
    import 'package:file_picker/file_picker.dart';   // for FilePickerResult