From 4f1dc72d3a50d27584596756eea9231faaf0d4eb Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Wed, 17 Nov 2021 14:03:03 +0530 Subject: [PATCH] added custom actions --- .../lib/src/attachment_actions_modal.dart | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/stream_chat_flutter/lib/src/attachment_actions_modal.dart b/packages/stream_chat_flutter/lib/src/attachment_actions_modal.dart index 89527a48..7b9f0d51 100644 --- a/packages/stream_chat_flutter/lib/src/attachment_actions_modal.dart +++ b/packages/stream_chat_flutter/lib/src/attachment_actions_modal.dart @@ -28,6 +28,7 @@ class AttachmentActionsModal extends StatelessWidget { this.showShowInChat = true, this.showSave = true, this.showDelete = true, + this.customActions = const [], }) : super(key: key); /// The message containing the attachments @@ -57,6 +58,9 @@ class AttachmentActionsModal extends StatelessWidget { /// Show delete option final bool showDelete; + /// List of custom actions + final List customActions; + /// Creates a copy of [MessageWidget] with specified attributes overridden. AttachmentActionsModal copyWith({ Key? key, @@ -69,6 +73,7 @@ class AttachmentActionsModal extends StatelessWidget { bool? showShowInChat, bool? showSave, bool? showDelete, + List? customActions, }) => AttachmentActionsModal( key: key ?? this.key, @@ -81,6 +86,7 @@ class AttachmentActionsModal extends StatelessWidget { showShowInChat: showShowInChat ?? this.showShowInChat, showSave: showSave ?? this.showSave, showDelete: showDelete ?? this.showDelete, + customActions: customActions ?? this.customActions, ); @override @@ -217,6 +223,16 @@ class AttachmentActionsModal extends StatelessWidget { }, color: theme.colorTheme.accentError, ), + ...customActions + .map( + (e) => _buildButton( + context, + e.actionTitle, + e.icon, + e.onTap, + ), + ) + .toList(), ] .map((e) => Align( alignment: Alignment.centerRight, @@ -239,7 +255,7 @@ class AttachmentActionsModal extends StatelessWidget { Widget _buildButton( context, String title, - StreamSvgIcon icon, + Widget icon, VoidCallback? onTap, { Color? color, Key? key, @@ -377,3 +393,15 @@ class _DownloadProgress { int get toPercentage => (received * 100) ~/ total; } + +class AttachmentAction { + String actionTitle; + Widget icon; + VoidCallback onTap; + + AttachmentAction({ + required this.actionTitle, + required this.icon, + required this.onTap, + }); +}