refactor!: initial attachments refactor.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2023-07-28 21:07:02 +05:30
committed by xsahil03x
parent eb6f0852e8
commit f246de55a1
61 changed files with 3628 additions and 1712 deletions
@@ -1,14 +1,13 @@
import 'dart:async';
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:chewie/chewie.dart';
import 'package:contextmenu/contextmenu.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:shimmer/shimmer.dart';
import 'package:stream_chat_flutter/platform_widget_builder/platform_widget_builder.dart';
import 'package:stream_chat_flutter/src/attachment/thumbnail/image_attachment_thumbnail.dart';
import 'package:stream_chat_flutter/src/context_menu_items/download_menu_item.dart';
import 'package:stream_chat_flutter/src/fullscreen_media/full_screen_media_widget.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
@@ -73,7 +72,7 @@ class _FullScreenMediaState extends State<StreamFullScreenMedia> {
_pageController = PageController(initialPage: widget.startIndex);
for (var i = 0; i < widget.mediaAttachmentPackages.length; i++) {
final attachment = widget.mediaAttachmentPackages[i].attachment;
if (attachment.type != 'video') continue;
if (attachment.type != AttachmentType.video) continue;
final package = VideoPackage(attachment, showControls: true);
videoPackages[attachment.id] = package;
}
@@ -92,7 +91,8 @@ class _FullScreenMediaState extends State<StreamFullScreenMedia> {
(it) => it.initialize(),
));
if (widget.autoplayVideos && currentAttachment.type == 'video') {
if (widget.autoplayVideos &&
currentAttachment.type == AttachmentType.video) {
final package = videoPackages.values
.firstWhere((e) => e._attachment == currentAttachment);
package._chewieController?.play();
@@ -281,10 +281,8 @@ class _FullScreenMediaState extends State<StreamFullScreenMedia> {
final currentAttachmentPackage =
widget.mediaAttachmentPackages[index];
final attachment = currentAttachmentPackage.attachment;
if (attachment.type == 'image' || attachment.type == 'giphy') {
final imageUrl = attachment.imageUrl ??
attachment.assetUrl ??
attachment.thumbUrl;
if (attachment.type == AttachmentType.image ||
attachment.type == AttachmentType.giphy) {
return ValueListenableBuilder<bool>(
valueListenable: _isDisplayingDetail,
builder: (context, isDisplayingDetail, _) =>
@@ -300,32 +298,40 @@ class _FullScreenMediaState extends State<StreamFullScreenMedia> {
attachment: attachment,
),
],
child: PhotoView(
imageProvider: (imageUrl == null &&
attachment.localUri != null &&
attachment.file?.bytes != null)
? Image.memory(attachment.file!.bytes!).image
: CachedNetworkImageProvider(imageUrl!),
errorBuilder: (_, __, ___) => const AttachmentError(),
loadingBuilder: (context, _) {
final image = Image.asset(
'images/placeholder.png',
fit: BoxFit.cover,
package: 'stream_chat_flutter',
);
final colorTheme =
StreamChatTheme.of(context).colorTheme;
return Shimmer.fromColors(
baseColor: colorTheme.disabled,
highlightColor: colorTheme.inputBg,
child: image,
);
},
child: PhotoView.customChild(
heroAttributes: PhotoViewHeroAttributes(
tag: attachment.id,
),
// imageProvider: (imageUrl == null &&
// attachment.localUri != null &&
// attachment.file?.bytes != null)
// ? Image.memory(attachment.file!.bytes!).image
// : CachedNetworkImageProvider(imageUrl!),
// errorBuilder: (_, __, ___) => const AttachmentError(),
// loadingBuilder: (context, _) {
// final image = Image.asset(
// 'images/placeholder.png',
// fit: BoxFit.cover,
// package: 'stream_chat_flutter',
// );
// final colorTheme =
// StreamChatTheme.of(context).colorTheme;
// return Shimmer.fromColors(
// baseColor: colorTheme.disabled,
// highlightColor: colorTheme.inputBg,
// child: image,
// );
// },
child: StreamImageAttachmentThumbnail(
image: attachment,
width: double.infinity,
height: double.infinity,
),
maxScale: PhotoViewComputedScale.covered,
minScale: PhotoViewComputedScale.contained,
heroAttributes: PhotoViewHeroAttributes(
tag: widget.mediaAttachmentPackages,
),
// heroAttributes: PhotoViewHeroAttributes(
// tag: widget.mediaAttachmentPackages,
// ),
backgroundDecoration: const BoxDecoration(
color: Colors.transparent,
),
@@ -333,7 +339,7 @@ class _FullScreenMediaState extends State<StreamFullScreenMedia> {
),
),
);
} else if (attachment.type == 'video') {
} else if (attachment.type == AttachmentType.video) {
final controller = videoPackages[attachment.id]!;
if (!controller.initialized) {
return const Center(