'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 1:[1]
Make sure the import
section is correct.
import 'dart:io'; // for File
import 'package:file_picker/file_picker.dart'; // for FilePickerResult
Solution 2:[2]
There are two errors.
- Two arguments are needed but you are sending only one
- The argument requests a list but you are sending an optional string.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maarten |
Solution 2 | Pankaj Kainthla |