pickFiles static method

Future<List<KatPlatformFile>> pickFiles({
  1. bool allowMultiple = false,
  2. KatFileType type = KatFileType.any,
  3. List<String>? allowedExtensions,
})

hàm này dùng để mở picker chọn file từ thiết bị

file_picker: ^12.0.0 removed the old FilePicker.platform / FilePickerResult / withData / withReadStream API - pickFiles now lives directly on FilePicker and always returns List<PlatformFile>, with bytes read lazily via PlatformFile.readAsBytes(). allowMultiple is also deprecated there in favor of a separate single-file pickFile, so that's what we call when allowMultiple is false.

allowedExtensions only takes effect when type is KatFileType.custom (file_picker requires it in that case, and ignores/rejects it otherwise) - use it to whitelist extensions instead of picking from one of file_picker's built-in categories (e.g. to allow documents and images but not video).

Implementation

static Future<List<KatPlatformFile>> pickFiles({
  bool allowMultiple = false,
  KatFileType type = KatFileType.any,
  List<String>? allowedExtensions,
}) async {
  if (!allowMultiple) {
    final file = await FilePicker.pickFile(
      type: type,
      allowedExtensions: allowedExtensions,
    );
    return file == null ? [] : [file];
  }
  return FilePicker.pickFiles(
    type: type,
    allowedExtensions: allowedExtensions,
  );
}