diff --git a/lib/blocs/fs_entry_preview/fs_entry_preview_cubit.dart b/lib/blocs/fs_entry_preview/fs_entry_preview_cubit.dart index aeea37ac17..84ec500007 100644 --- a/lib/blocs/fs_entry_preview/fs_entry_preview_cubit.dart +++ b/lib/blocs/fs_entry_preview/fs_entry_preview_cubit.dart @@ -32,8 +32,8 @@ class FsEntryPreviewCubit extends Cubit { final SecretKey? _fileKey; StreamSubscription? _entrySubscription; - static final ValueNotifier imagePreviewNotifier = - ValueNotifier(ImagePreviewNotification()); + static final ValueNotifier imagePreviewNotifier = + ValueNotifier(null); final previewMaxFileSize = 1024 * 1024 * 100; final allowedPreviewContentTypes = []; @@ -180,10 +180,15 @@ class FsEntryPreviewCubit extends Cubit { FileEntry file, String dataUrl, ) async { + if (file.dataContentType == null) { + emit(FsEntryPreviewUnavailable()); + return; + } + imagePreviewNotifier.value = ImagePreviewNotification( isLoading: true, filename: file.name, - contentType: file.dataContentType, + contentType: file.dataContentType!, ); emit(FsEntryPreviewImage(previewUrl: dataUrl)); @@ -428,10 +433,16 @@ class FsEntryPreviewCubit extends Cubit { if (isClosed) { return; } + + if (file.dataContentType == null) { + emit(FsEntryPreviewUnavailable()); + return; + } + imagePreviewNotifier.value = ImagePreviewNotification( dataBytes: dataBytes, filename: file.name, - contentType: file.dataContentType, + contentType: file.dataContentType!, ); emit(FsEntryPreviewImage(previewUrl: dataUrl)); } diff --git a/lib/blocs/fs_entry_preview/image_preview_notification.dart b/lib/blocs/fs_entry_preview/image_preview_notification.dart index ed41501a9b..4af1c54b2a 100644 --- a/lib/blocs/fs_entry_preview/image_preview_notification.dart +++ b/lib/blocs/fs_entry_preview/image_preview_notification.dart @@ -3,15 +3,15 @@ import 'dart:typed_data'; class ImagePreviewNotification { bool isLoading; Uint8List? dataBytes; - String? filename; - String? contentType; + String filename; + String contentType; bool get isPreviewable => dataBytes != null; ImagePreviewNotification({ this.dataBytes, - this.filename, - this.contentType, + required this.filename, + required this.contentType, this.isLoading = false, }); } diff --git a/lib/pages/drive_detail/components/fs_entry_preview_widget.dart b/lib/pages/drive_detail/components/fs_entry_preview_widget.dart index 18961873fd..6f86011757 100644 --- a/lib/pages/drive_detail/components/fs_entry_preview_widget.dart +++ b/lib/pages/drive_detail/components/fs_entry_preview_widget.dart @@ -1358,6 +1358,10 @@ class _ImagePreviewWidgetState extends State { return ValueListenableBuilder( valueListenable: FsEntryPreviewCubit.imagePreviewNotifier, builder: (context, imagePreview, _) { + if (imagePreview == null) { + return const SizedBox.shrink(); + } + final isLoading = imagePreview.isLoading; if (!widget.isFullScreen) { @@ -1579,8 +1583,12 @@ class _ImagePreviewWidgetState extends State { child: ValueListenableBuilder( valueListenable: FsEntryPreviewCubit.imagePreviewNotifier, builder: (context, imagePreview, _) { - final filename = imagePreview.filename!; - final contentType = imagePreview.contentType!; + if (imagePreview == null) { + return const SizedBox.shrink(); + } + + final filename = imagePreview.filename; + final contentType = imagePreview.contentType; final fileNameWithoutExtension = getBasenameWithoutExtension(filePath: filename); return Column(