added attachment actions modal builder

This commit is contained in:
Deven Joshi
2021-11-15 18:00:45 +05:30
parent 81508ac8ba
commit 5740e53ada
7 changed files with 71 additions and 43 deletions
@@ -18,6 +18,7 @@ class GiphyAttachment extends AttachmentWidget {
this.onShowMessage, this.onShowMessage,
this.onReturnAction, this.onReturnAction,
this.onAttachmentTap, this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super( }) : super(
key: key, key: key,
message: message, message: message,
@@ -34,6 +35,8 @@ class GiphyAttachment extends AttachmentWidget {
/// Callback when attachment is tapped /// Callback when attachment is tapped
final VoidCallback? onAttachmentTap; final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final imageUrl = final imageUrl =
@@ -250,6 +253,7 @@ class GiphyAttachment extends AttachmentWidget {
userName: message.user?.name, userName: message.user?.name,
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
), ),
); );
}, },
@@ -21,6 +21,7 @@ class ImageAttachment extends AttachmentWidget {
this.onShowMessage, this.onShowMessage,
this.onReturnAction, this.onReturnAction,
this.onAttachmentTap, this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super( }) : super(
key: key, key: key,
message: message, message: message,
@@ -43,6 +44,8 @@ class ImageAttachment extends AttachmentWidget {
/// Callback when attachment is tapped /// Callback when attachment is tapped
final VoidCallback? onAttachmentTap; final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override @override
Widget build(BuildContext context) => source.when( Widget build(BuildContext context) => source.when(
local: () { local: () {
@@ -145,6 +148,8 @@ class ImageAttachment extends AttachmentWidget {
userName: message.user?.name, userName: message.user?.name,
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
attachmentActionsModalBuilder:
attachmentActionsModalBuilder,
), ),
); );
}, },
@@ -18,6 +18,7 @@ class VideoAttachment extends AttachmentWidget {
this.onShowMessage, this.onShowMessage,
this.onReturnAction, this.onReturnAction,
this.onAttachmentTap, this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super( }) : super(
key: key, key: key,
message: message, message: message,
@@ -37,6 +38,8 @@ class VideoAttachment extends AttachmentWidget {
/// Callback when attachment is tapped /// Callback when attachment is tapped
final VoidCallback? onAttachmentTap; final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override @override
Widget build(BuildContext context) => source.when( Widget build(BuildContext context) => source.when(
local: () { local: () {
@@ -91,6 +94,8 @@ class VideoAttachment extends AttachmentWidget {
userName: message.user?.name, userName: message.user?.name,
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
attachmentActionsModalBuilder:
attachmentActionsModalBuilder,
), ),
), ),
), ),
@@ -57,6 +57,32 @@ class AttachmentActionsModal extends StatelessWidget {
/// Show delete option /// Show delete option
final bool showDelete; final bool showDelete;
/// Creates a copy of [MessageWidget] with specified attributes overridden.
AttachmentActionsModal copyWith({
Key? key,
int? currentIndex,
Message? message,
VoidCallback? onShowMessage,
AttachmentDownloader? imageDownloader,
AttachmentDownloader? fileDownloader,
bool? showReply,
bool? showShowInChat,
bool? showSave,
bool? showDelete,
}) =>
AttachmentActionsModal(
key: key ?? this.key,
currentIndex: currentIndex ?? this.currentIndex,
message: message ?? this.message,
onShowMessage: onShowMessage ?? this.onShowMessage,
imageDownloader: imageDownloader ?? this.imageDownloader,
fileDownloader: fileDownloader ?? this.fileDownloader,
showReply: showReply ?? this.showReply,
showShowInChat: showShowInChat ?? this.showShowInChat,
showSave: showSave ?? this.showSave,
showDelete: showDelete ?? this.showDelete,
);
@override @override
Widget build(BuildContext context) => GestureDetector( Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
@@ -33,10 +33,7 @@ class FullScreenMedia extends StatefulWidget {
this.startIndex = 0, this.startIndex = 0,
String? userName, String? userName,
this.onShowMessage, this.onShowMessage,
this.showReply = true, this.attachmentActionsModalBuilder,
this.showShowInChat = true,
this.showSave = true,
this.showDelete = true,
}) : userName = userName ?? '', }) : userName = userName ?? '',
super(key: key); super(key: key);
@@ -55,17 +52,7 @@ class FullScreenMedia extends StatefulWidget {
/// Callback for when show message is tapped /// Callback for when show message is tapped
final ShowMessageCallback? onShowMessage; final ShowMessageCallback? onShowMessage;
/// Show reply option final AttachmentActionsBuilder? attachmentActionsModalBuilder;
final bool showReply;
/// Show show in chat option
final bool showShowInChat;
/// Show save option
final bool showSave;
/// Show delete option
final bool showDelete;
@override @override
_FullScreenMediaState createState() => _FullScreenMediaState(); _FullScreenMediaState createState() => _FullScreenMediaState();
@@ -212,10 +199,8 @@ class _FullScreenMediaState extends State<FullScreenMedia>
StreamChannel.of(context).channel, StreamChannel.of(context).channel,
); );
}, },
showReply: widget.showReply, attachmentActionsModalBuilder:
showShowInChat: widget.showShowInChat, widget.attachmentActionsModalBuilder,
showSave: widget.showSave,
showDelete: widget.showDelete,
), ),
if (!widget.message.isEphemeral) if (!widget.message.isEphemeral)
GalleryFooter( GalleryFooter(
@@ -6,6 +6,12 @@ import 'package:stream_chat_flutter/src/stream_svg_icon.dart';
import 'package:stream_chat_flutter/src/theme/themes.dart'; import 'package:stream_chat_flutter/src/theme/themes.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
typedef AttachmentActionsBuilder = Widget Function(
BuildContext context,
Attachment attachment,
AttachmentActionsModal defaultActionsModal,
);
/// Header/AppBar widget for media display screen /// Header/AppBar widget for media display screen
class GalleryHeader extends StatelessWidget implements PreferredSizeWidget { class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
/// Creates a channel header /// Creates a channel header
@@ -21,10 +27,7 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
this.userName = '', this.userName = '',
this.sentAt = '', this.sentAt = '',
this.backgroundColor, this.backgroundColor,
this.showReply = true, this.attachmentActionsModalBuilder,
this.showShowInChat = true,
this.showSave = true,
this.showDelete = true,
}) : preferredSize = const Size.fromHeight(kToolbarHeight), }) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key); super(key: key);
@@ -59,17 +62,7 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color of this [GalleryHeader]. /// The background color of this [GalleryHeader].
final Color? backgroundColor; final Color? backgroundColor;
/// Show reply option final AttachmentActionsBuilder? attachmentActionsModalBuilder;
final bool showReply;
/// Show show in chat option
final bool showShowInChat;
/// Show save option
final bool showSave;
/// Show delete option
final bool showDelete;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -139,21 +132,26 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
final galleryHeaderThemeData = final galleryHeaderThemeData =
StreamChatTheme.of(context).galleryHeaderTheme; StreamChatTheme.of(context).galleryHeaderTheme;
final defaultModal = AttachmentActionsModal(
message: message,
currentIndex: currentIndex,
onShowMessage: onShowMessage,
);
final effectiveModal = attachmentActionsModalBuilder?.call(
context,
message.attachments[currentIndex],
defaultModal,
) ??
defaultModal;
final result = await showDialog( final result = await showDialog(
useRootNavigator: false, useRootNavigator: false,
context: context, context: context,
barrierColor: galleryHeaderThemeData.bottomSheetBarrierColor, barrierColor: galleryHeaderThemeData.bottomSheetBarrierColor,
builder: (context) => StreamChannel( builder: (context) => StreamChannel(
channel: channel, channel: channel,
child: AttachmentActionsModal( child: effectiveModal,
message: message,
currentIndex: currentIndex,
onShowMessage: onShowMessage,
showReply: showReply,
showShowInChat: showShowInChat,
showSave: showSave,
showDelete: showDelete,
),
), ),
); );
@@ -16,6 +16,7 @@ class ImageGroup extends StatelessWidget {
this.onReturnAction, this.onReturnAction,
this.onShowMessage, this.onShowMessage,
this.onAttachmentTap, this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super(key: key); }) : super(key: key);
/// List of attachments to show /// List of attachments to show
@@ -39,6 +40,8 @@ class ImageGroup extends StatelessWidget {
/// Callback for when show message is tapped /// Callback for when show message is tapped
final ShowMessageCallback? onShowMessage; final ShowMessageCallback? onShowMessage;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override @override
Widget build(BuildContext context) => ConstrainedBox( Widget build(BuildContext context) => ConstrainedBox(
constraints: BoxConstraints.loose(size), constraints: BoxConstraints.loose(size),
@@ -138,6 +141,7 @@ class ImageGroup extends StatelessWidget {
userName: message.user?.name, userName: message.user?.name,
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
), ),
), ),
), ),
@@ -151,5 +155,6 @@ class ImageGroup extends StatelessWidget {
message: message, message: message,
messageTheme: messageTheme, messageTheme: messageTheme,
onAttachmentTap: () => _onTap(context, index), onAttachmentTap: () => _onTap(context, index),
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
); );
} }