refactor: improve fullscreen_media, minor changes.

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 572207c354
commit 93b4158897
12 changed files with 135 additions and 465 deletions
@@ -1,6 +1,7 @@
export 'attachment_error.dart';
export 'attachment_upload_state_builder.dart';
export 'file_attachment.dart';
export 'gallery_attachment.dart';
export 'giphy_attachment.dart';
export 'image_attachment.dart';
export 'url_attachment.dart';
export 'video_attachment.dart';
@@ -1,33 +0,0 @@
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// {@template attachmentError}
/// Widget for building in case of error
/// {@endtemplate}
class AttachmentError extends StatelessWidget {
/// {@macro attachmentError}
const AttachmentError({
super.key,
this.constraints,
});
/// constraints of error
final BoxConstraints? constraints;
@override
Widget build(BuildContext context) {
return Center(
child: Container(
constraints: constraints ?? const BoxConstraints.expand(),
color:
StreamChatTheme.of(context).colorTheme.accentError.withOpacity(0.1),
child: Center(
child: Icon(
Icons.error_outline,
color: StreamChatTheme.of(context).colorTheme.textHighEmphasis,
),
),
),
);
}
}
@@ -1,51 +0,0 @@
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// {@template attachmentTitle}
/// Title for attachments
/// {@endtemplate}
class StreamAttachmentTitle extends StatelessWidget {
/// {@macro attachmentTitle}
const StreamAttachmentTitle({
super.key,
required this.attachment,
required this.messageTheme,
});
/// Theme to apply to text
final StreamMessageThemeData messageTheme;
/// Attachment data to display
final Attachment attachment;
@override
Widget build(BuildContext context) {
final ogScrapeUrl = attachment.ogScrapeUrl;
return GestureDetector(
onTap: () {
final ogScrapeUrl = attachment.ogScrapeUrl;
if (ogScrapeUrl != null) launchURL(context, ogScrapeUrl);
},
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (attachment.title != null)
Text(
attachment.title!,
overflow: TextOverflow.ellipsis,
style: messageTheme.messageTextStyle?.copyWith(
color: StreamChatTheme.of(context).colorTheme.accentPrimary,
fontWeight: FontWeight.bold,
),
),
if (ogScrapeUrl != null)
Text(ogScrapeUrl, style: messageTheme.messageTextStyle),
],
),
),
);
}
}
@@ -68,67 +68,39 @@ class StreamGiphyAttachment extends StatelessWidget {
borderRadius: BorderRadius.circular(14),
);
return Hero(
tag: giphy.id,
child: Container(
constraints: constraints,
clipBehavior: Clip.hardEdge,
decoration: ShapeDecoration(shape: shape),
child: AspectRatio(
aspectRatio: giphySize?.aspectRatio ?? 1,
child: Stack(
alignment: Alignment.center,
children: [
StreamGiphyAttachmentThumbnail(
type: type,
giphy: giphy,
fit: fit,
width: double.infinity,
height: double.infinity,
),
if (giphy.uploadState.isSuccess)
const Positioned(
bottom: 8,
left: 8,
child: GiphyChip(),
)
else
Padding(
padding: const EdgeInsets.all(8),
child: StreamAttachmentUploadStateBuilder(
message: message,
attachment: giphy,
),
return Container(
constraints: constraints,
clipBehavior: Clip.hardEdge,
decoration: ShapeDecoration(shape: shape),
child: AspectRatio(
aspectRatio: giphySize?.aspectRatio ?? 1,
child: Stack(
alignment: Alignment.center,
children: [
StreamGiphyAttachmentThumbnail(
type: type,
giphy: giphy,
fit: fit,
width: double.infinity,
height: double.infinity,
),
if (giphy.uploadState.isSuccess)
const Positioned(
bottom: 8,
left: 8,
child: GiphyChip(),
)
else
Padding(
padding: const EdgeInsets.all(8),
child: StreamAttachmentUploadStateBuilder(
message: message,
attachment: giphy,
),
],
),
),
],
),
),
);
}
// Future<void> _onTap(BuildContext context) async {
// if (onAttachmentTap != null) {
// return onAttachmentTap!();
// }
//
// await Navigator.of(context).push(
// MaterialPageRoute(
// builder: (_) {
// final channel = StreamChannel.of(context).channel;
// return StreamChannel(
// channel: channel,
// child: StreamFullScreenMediaBuilder(
// mediaAttachmentPackages: message.getAttachmentPackageList(),
// startIndex: message.attachments.indexOf(giphy),
// userName: message.user!.name,
// onShowMessage: onShowMessage,
// onReplyMessage: onReplyMessage,
// attachmentActionsModalBuilder: attachmentActionsModalBuilder,
// ),
// );
// },
// ),
// );
// }
}
@@ -103,31 +103,3 @@ class StreamImageAttachment extends StatelessWidget {
);
}
}
// Future<void> _onTap(
// BuildContext context,
// int index,
// ) async {
// if (onAttachmentTap != null) {
// return onAttachmentTap!();
// }
//
// final channel = StreamChannel.of(context).channel;
//
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => StreamChannel(
// channel: channel,
// child: StreamFullScreenMediaBuilder(
// mediaAttachmentPackages: message.getAttachmentPackageList(),
// startIndex: index,
// userName: message.user!.name,
// onShowMessage: onShowMessage,
// onReplyMessage: onReplyMessage,
// attachmentActionsModalBuilder: attachmentActionsModalBuilder,
// ),
// ),
// ),
// );
// }
// }