diff --git a/packages/katana_picker/lib/adapter/file_picker_adapter.dart b/packages/katana_picker/lib/adapter/file_picker_adapter.dart index 8d15421b1..c38213091 100644 --- a/packages/katana_picker/lib/adapter/file_picker_adapter.dart +++ b/packages/katana_picker/lib/adapter/file_picker_adapter.dart @@ -20,10 +20,10 @@ class FilePickerAdapter extends PickerAdapter { throw Exception("File not found."); } return files.mapAndRemoveEmpty((file) { - if (file.path == null || file.bytes == null) { + if (file.path == null && file.bytes == null) { return null; } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); }); case PickerMediaType.video: final res = await FilePicker.platform.pickFiles( @@ -36,10 +36,10 @@ class FilePickerAdapter extends PickerAdapter { throw Exception("File not found."); } return files.mapAndRemoveEmpty((file) { - if (file.path == null || file.bytes == null) { + if (file.path == null && file.bytes == null) { return null; } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); }); default: final res = await FilePicker.platform.pickFiles( @@ -51,10 +51,10 @@ class FilePickerAdapter extends PickerAdapter { throw Exception("File not found."); } return files.mapAndRemoveEmpty((file) { - if (file.path == null || file.bytes == null) { + if (file.path == null && file.bytes == null) { return null; } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); }); } } @@ -71,29 +71,29 @@ class FilePickerAdapter extends PickerAdapter { type: FileType.image, ); final file = res?.files.firstOrNull; - if (file == null || file.path == null || file.bytes == null) { + if (file == null || (file.path == null && file.bytes == null)) { throw Exception("File not found."); } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); case PickerMediaType.video: final res = await FilePicker.platform.pickFiles( dialogTitle: dialogTitle, type: FileType.video, ); final file = res?.files.firstOrNull; - if (file == null || file.path == null || file.bytes == null) { + if (file == null || (file.path == null && file.bytes == null)) { throw Exception("File not found."); } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); default: final res = await FilePicker.platform.pickFiles( dialogTitle: dialogTitle, ); final file = res?.files.firstOrNull; - if (file == null || file.path == null || file.bytes == null) { + if (file == null || (file.path == null && file.bytes == null)) { throw Exception("File not found."); } - return PickerValue(path: file.path!, bytes: file.bytes!); + return PickerValue(path: file.path, bytes: file.bytes); } } diff --git a/packages/katana_picker/lib/src/picker_value.dart b/packages/katana_picker/lib/src/picker_value.dart index e77f56bfd..70ba2d22c 100644 --- a/packages/katana_picker/lib/src/picker_value.dart +++ b/packages/katana_picker/lib/src/picker_value.dart @@ -3,12 +3,13 @@ part of katana_picker; @immutable class PickerValue { const PickerValue({ - required this.path, - required this.bytes, - }); + this.path, + this.bytes, + }) : assert(path != null || bytes != null, + "[Either [path] or [bytes] must be non-null."); - final String path; - final Uint8List bytes; + final String? path; + final Uint8List? bytes; @override int get hashCode => path.hashCode ^ bytes.hashCode;