showMaterialFilePicker function
Future<void>
showMaterialFilePicker({
- BuildContext? context,
- FileType fileType = FileType.any,
- List<
String> ? allowedExtensions, - ValueChanged<
PlatformFile> ? onChanged,
Allows selection of a file.
Implementation
Future<void> showMaterialFilePicker({
BuildContext? context,
/// The type of the file to retrieve (filter)
FileType fileType = FileType.any,
/// What allowed extensions to look for
List<String>? allowedExtensions,
/// Function that gets called when the value is changed
ValueChanged<PlatformFile>? onChanged,
}) async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: fileType,
withData: true,
allowMultiple: false,
allowedExtensions: allowedExtensions,
);
if (result != null && result.files.length == 1) {
PlatformFile file = result.files.single;
if (onChanged != null) onChanged(file);
}
}