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.onReturnAction,
this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super(
key: key,
message: message,
@@ -34,6 +35,8 @@ class GiphyAttachment extends AttachmentWidget {
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
Widget build(BuildContext context) {
final imageUrl =
@@ -250,6 +253,7 @@ class GiphyAttachment extends AttachmentWidget {
userName: message.user?.name,
message: message,
onShowMessage: onShowMessage,
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
),
);
},
@@ -21,6 +21,7 @@ class ImageAttachment extends AttachmentWidget {
this.onShowMessage,
this.onReturnAction,
this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super(
key: key,
message: message,
@@ -43,6 +44,8 @@ class ImageAttachment extends AttachmentWidget {
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
Widget build(BuildContext context) => source.when(
local: () {
@@ -145,6 +148,8 @@ class ImageAttachment extends AttachmentWidget {
userName: message.user?.name,
message: message,
onShowMessage: onShowMessage,
attachmentActionsModalBuilder:
attachmentActionsModalBuilder,
),
);
},
@@ -18,6 +18,7 @@ class VideoAttachment extends AttachmentWidget {
this.onShowMessage,
this.onReturnAction,
this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super(
key: key,
message: message,
@@ -37,6 +38,8 @@ class VideoAttachment extends AttachmentWidget {
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
Widget build(BuildContext context) => source.when(
local: () {
@@ -91,6 +94,8 @@ class VideoAttachment extends AttachmentWidget {
userName: message.user?.name,
message: message,
onShowMessage: onShowMessage,
attachmentActionsModalBuilder:
attachmentActionsModalBuilder,
),
),
),
@@ -57,6 +57,32 @@ class AttachmentActionsModal extends StatelessWidget {
/// Show delete option
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
Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.translucent,
@@ -33,10 +33,7 @@ class FullScreenMedia extends StatefulWidget {
this.startIndex = 0,
String? userName,
this.onShowMessage,
this.showReply = true,
this.showShowInChat = true,
this.showSave = true,
this.showDelete = true,
this.attachmentActionsModalBuilder,
}) : userName = userName ?? '',
super(key: key);
@@ -55,17 +52,7 @@ class FullScreenMedia extends StatefulWidget {
/// Callback for when show message is tapped
final ShowMessageCallback? onShowMessage;
/// Show reply option
final bool showReply;
/// Show show in chat option
final bool showShowInChat;
/// Show save option
final bool showSave;
/// Show delete option
final bool showDelete;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
_FullScreenMediaState createState() => _FullScreenMediaState();
@@ -212,10 +199,8 @@ class _FullScreenMediaState extends State<FullScreenMedia>
StreamChannel.of(context).channel,
);
},
showReply: widget.showReply,
showShowInChat: widget.showShowInChat,
showSave: widget.showSave,
showDelete: widget.showDelete,
attachmentActionsModalBuilder:
widget.attachmentActionsModalBuilder,
),
if (!widget.message.isEphemeral)
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_core/stream_chat_flutter_core.dart';
typedef AttachmentActionsBuilder = Widget Function(
BuildContext context,
Attachment attachment,
AttachmentActionsModal defaultActionsModal,
);
/// Header/AppBar widget for media display screen
class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
/// Creates a channel header
@@ -21,10 +27,7 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
this.userName = '',
this.sentAt = '',
this.backgroundColor,
this.showReply = true,
this.showShowInChat = true,
this.showSave = true,
this.showDelete = true,
this.attachmentActionsModalBuilder,
}) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key);
@@ -59,17 +62,7 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color of this [GalleryHeader].
final Color? backgroundColor;
/// Show reply option
final bool showReply;
/// Show show in chat option
final bool showShowInChat;
/// Show save option
final bool showSave;
/// Show delete option
final bool showDelete;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
Widget build(BuildContext context) {
@@ -139,21 +132,26 @@ class GalleryHeader extends StatelessWidget implements PreferredSizeWidget {
final galleryHeaderThemeData =
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(
useRootNavigator: false,
context: context,
barrierColor: galleryHeaderThemeData.bottomSheetBarrierColor,
builder: (context) => StreamChannel(
channel: channel,
child: AttachmentActionsModal(
message: message,
currentIndex: currentIndex,
onShowMessage: onShowMessage,
showReply: showReply,
showShowInChat: showShowInChat,
showSave: showSave,
showDelete: showDelete,
),
child: effectiveModal,
),
);
@@ -16,6 +16,7 @@ class ImageGroup extends StatelessWidget {
this.onReturnAction,
this.onShowMessage,
this.onAttachmentTap,
this.attachmentActionsModalBuilder,
}) : super(key: key);
/// List of attachments to show
@@ -39,6 +40,8 @@ class ImageGroup extends StatelessWidget {
/// Callback for when show message is tapped
final ShowMessageCallback? onShowMessage;
final AttachmentActionsBuilder? attachmentActionsModalBuilder;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: BoxConstraints.loose(size),
@@ -138,6 +141,7 @@ class ImageGroup extends StatelessWidget {
userName: message.user?.name,
message: message,
onShowMessage: onShowMessage,
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
),
),
),
@@ -151,5 +155,6 @@ class ImageGroup extends StatelessWidget {
message: message,
messageTheme: messageTheme,
onAttachmentTap: () => _onTap(context, index),
attachmentActionsModalBuilder: attachmentActionsModalBuilder,
);
}