FilePickerCallback typedef

FilePickerCallback = Future<List<FileData>?> Function({required bool allowMultiple, List<String>? allowedExtensions})

Callback type for custom file picker implementations.

Users of the formio_flutter package should implement this callback to provide their own file picking logic (e.g., using file_picker, image_picker, etc.)

Parameters:

  • allowMultiple: Whether multiple file selection is allowed
  • allowedExtensions: Optional list of allowed file extensions (without dots, e.g., 'jpg', 'png', 'pdf')

Returns a Future that resolves to:

  • A list of FileData objects if files were selected
  • null if the user cancelled the picker

Example implementation:

Future<List<FileData>?> myFilePicker({
  required bool allowMultiple,
  List<String>? allowedExtensions,
}) async {
  final result = await FilePicker.platform.pickFiles(
    allowMultiple: allowMultiple,
    type: allowedExtensions != null ? FileType.custom : FileType.any,
    allowedExtensions: allowedExtensions,
  );

  if (result != null) {
    return result.files.map((file) => FileData(
      name: file.name,
      bytes: file.bytes,
      path: file.path,
    )).toList();
  }
  return null;
}

Implementation

typedef FilePickerCallback = Future<List<FileData>?> Function({
  required bool allowMultiple,
  List<String>? allowedExtensions,
});