fix file attachment in messageinput
This commit is contained in:
@@ -159,6 +159,7 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
shape: _getDefaultShape(context),
|
shape: _getDefaultShape(context),
|
||||||
child: source.when(
|
child: source.when(
|
||||||
local: () => VideoThumbnailImage(
|
local: () => VideoThumbnailImage(
|
||||||
|
fit: BoxFit.cover,
|
||||||
video: attachment.file!.path!,
|
video: attachment.file!.path!,
|
||||||
placeholderBuilder: (_) => const Center(
|
placeholderBuilder: (_) => const Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@@ -169,6 +170,7 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
network: () => VideoThumbnailImage(
|
network: () => VideoThumbnailImage(
|
||||||
|
fit: BoxFit.cover,
|
||||||
video: attachment.assetUrl!,
|
video: attachment.assetUrl!,
|
||||||
placeholderBuilder: (_) => const Center(
|
placeholderBuilder: (_) => const Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@@ -212,50 +214,42 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
final attachmentId = attachment.id;
|
final attachmentId = attachment.id;
|
||||||
var trailingWidget = trailing;
|
var trailingWidget = trailing;
|
||||||
trailingWidget ??= attachment.uploadState.when(
|
trailingWidget ??= attachment.uploadState.when(
|
||||||
preparing: () => Padding(
|
preparing: () => Padding(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
child: _buildButton(
|
child: _buildButton(
|
||||||
icon: StreamSvgIcon.close(color: theme.colorTheme.white),
|
icon: StreamSvgIcon.close(color: theme.colorTheme.white),
|
||||||
fillColor: theme.colorTheme.overlayDark,
|
fillColor: theme.colorTheme.overlayDark,
|
||||||
onPressed: () => channel.cancelAttachmentUpload(attachmentId),
|
onPressed: () => channel.cancelAttachmentUpload(attachmentId),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
inProgress: (_, __) => Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: _buildButton(
|
||||||
|
icon: StreamSvgIcon.close(color: theme.colorTheme.white),
|
||||||
|
fillColor: theme.colorTheme.overlayDark,
|
||||||
|
onPressed: () => channel.cancelAttachmentUpload(attachmentId),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
success: () => Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: CircleAvatar(
|
||||||
|
backgroundColor: theme.colorTheme.accentBlue,
|
||||||
|
maxRadius: 12,
|
||||||
|
child: StreamSvgIcon.check(color: theme.colorTheme.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
failed: (_) => Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: _buildButton(
|
||||||
|
icon: StreamSvgIcon.retry(color: theme.colorTheme.white),
|
||||||
|
fillColor: theme.colorTheme.overlayDark,
|
||||||
|
onPressed: () => channel.retryAttachmentUpload(
|
||||||
|
message.id,
|
||||||
|
attachmentId,
|
||||||
),
|
),
|
||||||
inProgress: (_, __) => Padding(
|
),
|
||||||
padding: const EdgeInsets.all(8),
|
),
|
||||||
child: _buildButton(
|
);
|
||||||
icon: StreamSvgIcon.close(color: theme.colorTheme.white),
|
|
||||||
fillColor: theme.colorTheme.overlayDark,
|
|
||||||
onPressed: () => channel.cancelAttachmentUpload(attachmentId),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
success: () => Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: CircleAvatar(
|
|
||||||
backgroundColor: theme.colorTheme.accentBlue,
|
|
||||||
maxRadius: 12,
|
|
||||||
child: StreamSvgIcon.check(color: theme.colorTheme.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
failed: (_) => Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: _buildButton(
|
|
||||||
icon: StreamSvgIcon.retry(color: theme.colorTheme.white),
|
|
||||||
fillColor: theme.colorTheme.overlayDark,
|
|
||||||
onPressed: () => channel.retryAttachmentUpload(
|
|
||||||
message.id,
|
|
||||||
attachmentId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
) ??
|
|
||||||
IconButton(
|
|
||||||
icon: StreamSvgIcon.cloudDownload(color: theme.colorTheme.black),
|
|
||||||
visualDensity: VisualDensity.compact,
|
|
||||||
splashRadius: 16,
|
|
||||||
onPressed: () {
|
|
||||||
launchURL(context, attachment.assetUrl);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message.status == MessageSendingStatus.sent) {
|
if (message.status == MessageSendingStatus.sent) {
|
||||||
trailingWidget = IconButton(
|
trailingWidget = IconButton(
|
||||||
@@ -281,25 +275,17 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
color: theme.colorTheme.grey,
|
color: theme.colorTheme.grey,
|
||||||
);
|
);
|
||||||
return attachment.uploadState.when(
|
return attachment.uploadState.when(
|
||||||
preparing: () => UploadProgressIndicator(
|
preparing: () => Text(fileSize(size), style: textStyle),
|
||||||
uploaded: 0,
|
inProgress: (sent, total) => UploadProgressIndicator(
|
||||||
total: double.maxFinite.toInt(),
|
uploaded: sent,
|
||||||
showBackground: false,
|
total: total,
|
||||||
padding: EdgeInsets.zero,
|
showBackground: false,
|
||||||
textStyle: textStyle,
|
padding: EdgeInsets.zero,
|
||||||
progressIndicatorColor: theme.colorTheme.accentBlue,
|
textStyle: textStyle,
|
||||||
),
|
progressIndicatorColor: theme.colorTheme.accentBlue,
|
||||||
inProgress: (sent, total) => UploadProgressIndicator(
|
),
|
||||||
uploaded: sent,
|
success: () => Text(fileSize(size), style: textStyle),
|
||||||
total: total,
|
failed: (_) => Text('UPLOAD ERROR', style: textStyle),
|
||||||
showBackground: false,
|
);
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
textStyle: textStyle,
|
|
||||||
progressIndicatorColor: theme.colorTheme.accentBlue,
|
|
||||||
),
|
|
||||||
success: () => Text(fileSize(size), style: textStyle),
|
|
||||||
failed: (_) => Text('UPLOAD ERROR', style: textStyle),
|
|
||||||
) ??
|
|
||||||
Text(fileSize(size), style: textStyle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1114,8 +1114,8 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (file.size! > widget.maxAttachmentSize) {
|
if (file.size! > widget.maxAttachmentSize) {
|
||||||
if (medium.type == AssetType.video) {
|
if (medium.type == AssetType.video && file.path != null) {
|
||||||
final mediaInfo = await (VideoService.compressVideo(file.path)
|
final mediaInfo = await (VideoService.compressVideo(file.path!)
|
||||||
as FutureOr<MediaInfo>);
|
as FutureOr<MediaInfo>);
|
||||||
|
|
||||||
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||||
@@ -1510,7 +1510,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
(e) => ClipRRect(
|
(e) => ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
child: FileAttachment(
|
child: FileAttachment(
|
||||||
message: Message(), // dummy message
|
message: Message(
|
||||||
|
status: MessageSendingStatus.sending,
|
||||||
|
), // dummy message
|
||||||
attachment: e,
|
attachment: e,
|
||||||
size: Size(
|
size: Size(
|
||||||
MediaQuery.of(context).size.width * 0.65,
|
MediaQuery.of(context).size.width * 0.65,
|
||||||
@@ -1898,12 +1900,13 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
final attachment = Attachment(
|
final attachment = Attachment(
|
||||||
file: file,
|
file: file,
|
||||||
type: attachmentType,
|
type: attachmentType,
|
||||||
|
uploadState: const UploadState.preparing(),
|
||||||
extraData: extraDataMap,
|
extraData: extraDataMap,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (file.size! > widget.maxAttachmentSize) {
|
if (file.size! > widget.maxAttachmentSize) {
|
||||||
if (attachmentType == 'Video') {
|
if (attachmentType == 'video' && file.path != null) {
|
||||||
final mediaInfo = await (VideoService.compressVideo(file.path)
|
final mediaInfo = await (VideoService.compressVideo(file.path!)
|
||||||
as FutureOr<MediaInfo>);
|
as FutureOr<MediaInfo>);
|
||||||
|
|
||||||
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ class IVideoService {
|
|||||||
/// );
|
/// );
|
||||||
/// debugPrint(info.toJson());
|
/// debugPrint(info.toJson());
|
||||||
/// ```
|
/// ```
|
||||||
Future<MediaInfo?> compressVideo(String? path) async => _lock.synchronized(
|
Future<MediaInfo?> compressVideo(String path) async => _lock.synchronized(
|
||||||
() => VideoCompress.compressVideo(
|
() => VideoCompress.compressVideo(
|
||||||
path!,
|
path,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user