feat(llc, ui): add support for thumbUrl in video attachment. (#1362)
* feat(llc, ui): add support for thumbUrl in file attachment. Signed-off-by: xsahil03x <[email protected]> * chore(ui): use widget.fit instead of hardcoded fit. Signed-off-by: xsahil03x <[email protected]> * fix analysis Signed-off-by: xsahil03x <[email protected]> Co-authored-by: Salvatore Giordano <[email protected]>
This commit is contained in:
co-authored by
Salvatore Giordano
parent
8b6c59929f
commit
1e9e942c46
@@ -1,5 +1,9 @@
|
||||
## Upcoming
|
||||
|
||||
✅ Added
|
||||
|
||||
- `VideoAttachment` now uses `thumbUrl` to show the thumbnail
|
||||
if it's available instead of generating them.
|
||||
- Expose `widthFactor` option in `MessageWidget`
|
||||
|
||||
## 5.0.1
|
||||
@@ -555,7 +559,7 @@ typedef ActionButtonBuilder = Widget Function(
|
||||
```
|
||||
|
||||
> **_NOTE:_** The last parameter is the default `ActionButton`
|
||||
You can call `.copyWith` to customize just a subset of properties.
|
||||
> You can call `.copyWith` to customize just a subset of properties.
|
||||
|
||||
- Added slow mode which allows a cooldown period after a user sends a message.
|
||||
|
||||
@@ -658,7 +662,7 @@ typedef MessageBuilder = Widget Function(
|
||||
```
|
||||
|
||||
> **_NOTE:_** the last parameter is the default `MessageWidget`
|
||||
You can call `.copyWith` to customize just a subset of properties
|
||||
> You can call `.copyWith` to customize just a subset of properties
|
||||
|
||||
|
||||
✅ Added
|
||||
@@ -728,7 +732,7 @@ typedef MessageBuilder = Widget Function(
|
||||
```
|
||||
|
||||
> **_NOTE:_** The last parameter is the default `MessageWidget`
|
||||
You can call `.copyWith` to customize just a subset of properties.
|
||||
> You can call `.copyWith` to customize just a subset of properties.
|
||||
|
||||
✅ Added
|
||||
|
||||
|
||||
@@ -195,7 +195,6 @@ class _FileTypeImage extends StatelessWidget {
|
||||
shape: _getDefaultShape(context),
|
||||
child: source.when(
|
||||
local: () => StreamVideoThumbnailImage(
|
||||
fit: BoxFit.cover,
|
||||
video: attachment.file!.path!,
|
||||
placeholderBuilder: (_) => const Center(
|
||||
child: SizedBox(
|
||||
@@ -206,7 +205,6 @@ class _FileTypeImage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
network: () => StreamVideoThumbnailImage(
|
||||
fit: BoxFit.cover,
|
||||
video: attachment.assetUrl!,
|
||||
placeholderBuilder: (_) => const Center(
|
||||
child: SizedBox(
|
||||
|
||||
@@ -42,9 +42,8 @@ class StreamVideoAttachment extends StreamAttachmentWidget {
|
||||
context,
|
||||
StreamVideoThumbnailImage(
|
||||
video: attachment.file!.path!,
|
||||
thumbUrl: attachment.thumbUrl,
|
||||
constraints: constraints,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __) => AttachmentError(constraints: constraints),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -56,9 +55,8 @@ class StreamVideoAttachment extends StreamAttachmentWidget {
|
||||
context,
|
||||
StreamVideoThumbnailImage(
|
||||
video: attachment.assetUrl!,
|
||||
thumbUrl: attachment.thumbUrl,
|
||||
constraints: constraints,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __) => AttachmentError(constraints: constraints),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -221,7 +221,6 @@ class _StreamGalleryFooterState extends State<StreamGalleryFooter> {
|
||||
child: StreamVideoThumbnailImage(
|
||||
video: (attachment.file?.path ??
|
||||
attachment.assetUrl)!,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -278,7 +278,6 @@ class _ParseAttachments extends StatelessWidget {
|
||||
key: ValueKey(attachment.assetUrl),
|
||||
video: attachment.file?.path ?? attachment.assetUrl!,
|
||||
constraints: BoxConstraints.loose(const Size(32, 32)),
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __) => AttachmentError(
|
||||
constraints: BoxConstraints.loose(const Size(32, 32)),
|
||||
),
|
||||
|
||||
@@ -1191,7 +1191,6 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
),
|
||||
),
|
||||
video: (attachment.file?.path ?? attachment.assetUrl)!,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
Positioned(
|
||||
left: 8,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import 'package:stream_chat_flutter/src/video/video_service.dart';
|
||||
@@ -14,16 +15,20 @@ class StreamVideoThumbnailImage extends StatefulWidget {
|
||||
const StreamVideoThumbnailImage({
|
||||
super.key,
|
||||
required this.video,
|
||||
this.thumbUrl,
|
||||
this.constraints,
|
||||
this.fit,
|
||||
this.fit = BoxFit.cover,
|
||||
this.format = ImageFormat.PNG,
|
||||
this.errorBuilder,
|
||||
this.placeholderBuilder,
|
||||
});
|
||||
|
||||
/// Video path
|
||||
/// Video path or url
|
||||
final String video;
|
||||
|
||||
/// Video thumbnail url
|
||||
final String? thumbUrl;
|
||||
|
||||
/// Contraints of attachments
|
||||
final BoxConstraints? constraints;
|
||||
|
||||
@@ -49,13 +54,20 @@ class _StreamVideoThumbnailImageState extends State<StreamVideoThumbnailImage> {
|
||||
late Future<Uint8List?> thumbnailFuture;
|
||||
late StreamChatThemeData _streamChatTheme;
|
||||
|
||||
void _generateThumbnail() {
|
||||
// Only generate thumbnail if the thumbnail url is not provided.
|
||||
if (widget.thumbUrl == null) {
|
||||
thumbnailFuture = StreamVideoService.generateVideoThumbnail(
|
||||
video: widget.video,
|
||||
imageFormat: widget.format,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
thumbnailFuture = StreamVideoService.generateVideoThumbnail(
|
||||
video: widget.video,
|
||||
imageFormat: widget.format,
|
||||
);
|
||||
_generateThumbnail();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -67,16 +79,41 @@ class _StreamVideoThumbnailImageState extends State<StreamVideoThumbnailImage> {
|
||||
@override
|
||||
void didUpdateWidget(covariant StreamVideoThumbnailImage oldWidget) {
|
||||
if (oldWidget.video != widget.video || oldWidget.format != widget.format) {
|
||||
thumbnailFuture = StreamVideoService.generateVideoThumbnail(
|
||||
video: widget.video,
|
||||
imageFormat: widget.format,
|
||||
);
|
||||
_generateThumbnail();
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final placeHolderWidget = widget.placeholderBuilder?.call(context) ??
|
||||
Shimmer.fromColors(
|
||||
baseColor: _streamChatTheme.colorTheme.disabled,
|
||||
highlightColor: _streamChatTheme.colorTheme.inputBg,
|
||||
child: Image.asset(
|
||||
'images/placeholder.png',
|
||||
fit: BoxFit.cover,
|
||||
height: widget.constraints?.maxHeight,
|
||||
width: widget.constraints?.maxWidth,
|
||||
package: 'stream_chat_flutter',
|
||||
),
|
||||
);
|
||||
|
||||
final errorWidget = widget.errorBuilder?.call(context, null) ??
|
||||
AttachmentError(constraints: widget.constraints);
|
||||
|
||||
final thumbUrl = widget.thumbUrl;
|
||||
if (thumbUrl != null) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: thumbUrl,
|
||||
fit: widget.fit,
|
||||
height: widget.constraints?.maxHeight,
|
||||
width: widget.constraints?.maxWidth,
|
||||
placeholder: (context, __) => placeHolderWidget,
|
||||
errorWidget: (context, url, error) => errorWidget,
|
||||
);
|
||||
}
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: widget.constraints ?? const BoxConstraints.expand(),
|
||||
child: FutureBuilder<Uint8List?>(
|
||||
@@ -86,30 +123,16 @@ class _StreamVideoThumbnailImageState extends State<StreamVideoThumbnailImage> {
|
||||
child: Builder(
|
||||
key: ValueKey<AsyncSnapshot<Uint8List?>>(snapshot),
|
||||
builder: (_) {
|
||||
if (snapshot.hasError) {
|
||||
return widget.errorBuilder?.call(context, snapshot.error) ??
|
||||
Center(
|
||||
child: StreamSvgIcon.error(),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasError) return errorWidget;
|
||||
|
||||
if (!snapshot.hasData) {
|
||||
return SizedBox(
|
||||
height: double.maxFinite,
|
||||
width: double.maxFinite,
|
||||
child: widget.placeholderBuilder?.call(context) ??
|
||||
Shimmer.fromColors(
|
||||
baseColor: _streamChatTheme.colorTheme.disabled,
|
||||
highlightColor: _streamChatTheme.colorTheme.inputBg,
|
||||
child: Image.asset(
|
||||
'images/placeholder.png',
|
||||
fit: BoxFit.cover,
|
||||
height: widget.constraints?.maxHeight,
|
||||
width: widget.constraints?.maxWidth,
|
||||
package: 'stream_chat_flutter',
|
||||
),
|
||||
),
|
||||
child: placeHolderWidget,
|
||||
);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: double.maxFinite,
|
||||
width: double.maxFinite,
|
||||
|
||||
Reference in New Issue
Block a user