fix: video thumbnails on web null error

This commit is contained in:
Gordon Hayes
2022-11-25 11:52:04 +01:00
parent ddd8310b96
commit 0db682ac86
7 changed files with 26 additions and 13 deletions
@@ -21,6 +21,9 @@ class _IVideoService {
///
/// Thumbnails are not supported on Web at this time.
///
/// If no [video] path is supplied, or if a thumbnail cannot be generated,
/// returns [generatePlaceholderThumbnail]. A stock placeholder image.
///
/// For desktop, you can specify the position of the video to generate
/// the thumbnail.
///
@@ -29,14 +32,14 @@ class _IVideoService {
/// creates lower quality of the thumbnail image, but it gets ignored for
/// PNG format.
Future<Uint8List?> generateVideoThumbnail({
required String video,
String? video,
ImageFormat imageFormat = ImageFormat.PNG,
int maxHeight = 0,
int maxWidth = 0,
int timeMs = 0,
int quality = 10,
}) async {
if (kIsWeb) {
if (kIsWeb || video == null) {
final placeholder = await generatePlaceholderThumbnail();
return placeholder;
}
@@ -8,13 +8,23 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:video_thumbnail/video_thumbnail.dart';
/// {@template streamVideoThumbnailImage}
/// Displays a video thumbnail for video attachments in a message.
/// Displays a video thumbnail for video attachments.
///
/// [thumbUrl] is used if provided.
///
/// Else [video] (path to local or remote video) is used to generate
/// a thumbnail from the video asset.
///
/// WARNING! a local path does not work on web.
///
/// If both [thumbUrl] and [video] are null, or if a thumbnail can't be
/// generated, a stock default image will be used.
/// {@endtemplate}
class StreamVideoThumbnailImage extends StatefulWidget {
/// {@macro streamVideoThumbnailImage}
const StreamVideoThumbnailImage({
super.key,
required this.video,
this.video,
this.thumbUrl,
this.constraints,
this.fit = BoxFit.cover,
@@ -24,7 +34,7 @@ class StreamVideoThumbnailImage extends StatefulWidget {
});
/// Video path or url
final String video;
final String? video;
/// Video thumbnail url
final String? thumbUrl;