Skip to content

Commit

Permalink
fix: Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Dec 20, 2022
1 parent 161f0f1 commit 43f208a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
24 changes: 12 additions & 12 deletions packages/katana_picker/lib/adapter/file_picker_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
});
}
}
Expand All @@ -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);
}
}

Expand Down
11 changes: 6 additions & 5 deletions packages/katana_picker/lib/src/picker_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 43f208a

Please sign in to comment.