add attachment builders parameter
This commit is contained in:
@@ -68,6 +68,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.showVideoFullScreen = true,
|
this.showVideoFullScreen = true,
|
||||||
this.onMentionTap,
|
this.onMentionTap,
|
||||||
this.onMessageActions,
|
this.onMessageActions,
|
||||||
|
this.attachmentBuilders,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -98,6 +99,9 @@ class MessageListView extends StatefulWidget {
|
|||||||
/// Function called on message long press
|
/// Function called on message long press
|
||||||
final Function(BuildContext, Message) onMessageActions;
|
final Function(BuildContext, Message) onMessageActions;
|
||||||
|
|
||||||
|
/// Map that defines a builder for an attachment type
|
||||||
|
final Map<String, AttachmentBuilder> attachmentBuilders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageListViewState createState() => _MessageListViewState();
|
_MessageListViewState createState() => _MessageListViewState();
|
||||||
}
|
}
|
||||||
@@ -157,6 +161,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
widget.showOtherMessageUsername,
|
widget.showOtherMessageUsername,
|
||||||
onMentionTap: widget.onMentionTap,
|
onMentionTap: widget.onMentionTap,
|
||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
@@ -219,6 +224,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
showVideoFullScreen: widget.showVideoFullScreen,
|
showVideoFullScreen: widget.showVideoFullScreen,
|
||||||
onMentionTap: widget.onMentionTap,
|
onMentionTap: widget.onMentionTap,
|
||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,6 +303,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
showOtherMessageUsername: widget.showOtherMessageUsername,
|
showOtherMessageUsername: widget.showOtherMessageUsername,
|
||||||
onMentionTap: widget.onMentionTap,
|
onMentionTap: widget.onMentionTap,
|
||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,6 +343,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
showOtherMessageUsername: widget.showOtherMessageUsername,
|
showOtherMessageUsername: widget.showOtherMessageUsername,
|
||||||
onMentionTap: widget.onMentionTap,
|
onMentionTap: widget.onMentionTap,
|
||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+70
-23
@@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
import 'package:jiffy/jiffy.dart';
|
import 'package:jiffy/jiffy.dart';
|
||||||
import 'package:stream_chat/stream_chat.dart';
|
import 'package:stream_chat/stream_chat.dart';
|
||||||
|
import 'package:stream_chat_flutter/src/file_attachment.dart';
|
||||||
import 'package:stream_chat_flutter/src/giphy_attachment.dart';
|
import 'package:stream_chat_flutter/src/giphy_attachment.dart';
|
||||||
import 'package:stream_chat_flutter/src/image_attachment.dart';
|
import 'package:stream_chat_flutter/src/image_attachment.dart';
|
||||||
import 'package:stream_chat_flutter/src/message_input.dart';
|
import 'package:stream_chat_flutter/src/message_input.dart';
|
||||||
@@ -19,9 +20,10 @@ import 'package:stream_chat_flutter/src/video_attachment.dart';
|
|||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import 'deleted_message.dart';
|
import 'deleted_message.dart';
|
||||||
import 'file_attachment.dart';
|
|
||||||
import 'stream_chat.dart';
|
import 'stream_chat.dart';
|
||||||
|
|
||||||
|
typedef AttachmentBuilder = Widget Function(BuildContext, Message, Attachment);
|
||||||
|
|
||||||
/// 
|
/// 
|
||||||
/// 
|
/// 
|
||||||
///
|
///
|
||||||
@@ -44,6 +46,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
this.onMentionTap,
|
this.onMentionTap,
|
||||||
this.showOtherMessageUsername = false,
|
this.showOtherMessageUsername = false,
|
||||||
this.showVideoFullScreen = true,
|
this.showVideoFullScreen = true,
|
||||||
|
this.attachmentBuilders,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function called on mention tap
|
/// Function called on mention tap
|
||||||
@@ -73,8 +76,11 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// True if the video player will allow fullscreen mode
|
/// True if the video player will allow fullscreen mode
|
||||||
final bool showVideoFullScreen;
|
final bool showVideoFullScreen;
|
||||||
|
|
||||||
|
/// Map that defines a builder for an attachment type
|
||||||
|
final Map<String, AttachmentBuilder> attachmentBuilders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageWidgetState createState() => _MessageWidgetState();
|
_MessageWidgetState createState() => _MessageWidgetState(attachmentBuilders);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MessageWidgetState extends State<MessageWidget>
|
class _MessageWidgetState extends State<MessageWidget>
|
||||||
@@ -91,6 +97,38 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
bool _isLastUser;
|
bool _isLastUser;
|
||||||
bool _isNextUser;
|
bool _isNextUser;
|
||||||
|
|
||||||
|
Map<String, AttachmentBuilder> _attachmentBuilders;
|
||||||
|
|
||||||
|
_MessageWidgetState(Map<String, AttachmentBuilder> attachmentBuilders) {
|
||||||
|
_attachmentBuilders = {
|
||||||
|
'image': (context, message, attachment) {
|
||||||
|
return ImageAttachment(
|
||||||
|
attachment: attachment,
|
||||||
|
messageTheme: _messageTheme,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'video': (context, message, attachment) {
|
||||||
|
return VideoAttachment(
|
||||||
|
enableFullScreen: widget.showVideoFullScreen,
|
||||||
|
attachment: attachment,
|
||||||
|
messageTheme: _messageTheme,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'giphy': (context, message, attachment) {
|
||||||
|
return GiphyAttachment(
|
||||||
|
attachment: attachment,
|
||||||
|
messageTheme: _messageTheme,
|
||||||
|
message: message,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'file': (context, message, attachment) {
|
||||||
|
return FileAttachment(
|
||||||
|
attachment: attachment,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}..addAll(attachmentBuilders ?? {});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
super.build(context);
|
super.build(context);
|
||||||
@@ -213,28 +251,37 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
nOfAttachmentWidgets++;
|
nOfAttachmentWidgets++;
|
||||||
|
|
||||||
Widget attachmentWidget;
|
Widget attachmentWidget;
|
||||||
if (attachment.type == 'video') {
|
final attachmentBuilder = _attachmentBuilders[attachment.type];
|
||||||
attachmentWidget = VideoAttachment(
|
if (attachmentBuilder == null) {
|
||||||
attachment: attachment,
|
return SizedBox();
|
||||||
messageTheme: _messageTheme,
|
|
||||||
enableFullScreen: widget.showVideoFullScreen,
|
|
||||||
);
|
|
||||||
} else if (attachment.type == 'giphy') {
|
|
||||||
attachmentWidget = GiphyAttachment(
|
|
||||||
attachment: attachment,
|
|
||||||
message: widget.message,
|
|
||||||
messageTheme: _messageTheme,
|
|
||||||
);
|
|
||||||
} else if (attachment.type == 'image') {
|
|
||||||
attachmentWidget = ImageAttachment(
|
|
||||||
attachment: attachment,
|
|
||||||
messageTheme: _messageTheme,
|
|
||||||
);
|
|
||||||
} else if (attachment.type == 'file') {
|
|
||||||
attachmentWidget = FileAttachment(
|
|
||||||
attachment: attachment,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
attachmentWidget = attachmentBuilder(
|
||||||
|
context,
|
||||||
|
widget.message,
|
||||||
|
attachment,
|
||||||
|
);
|
||||||
|
// if (attachment.type == 'video') {
|
||||||
|
// attachmentWidget = VideoAttachment(
|
||||||
|
// attachment: attachment,
|
||||||
|
// messageTheme: _messageTheme,
|
||||||
|
// enableFullScreen: widget.showVideoFullScreen,
|
||||||
|
// );
|
||||||
|
// } else if (attachment.type == 'giphy') {
|
||||||
|
// attachmentWidget = GiphyAttachment(
|
||||||
|
// attachment: attachment,
|
||||||
|
// message: widget.message,
|
||||||
|
// messageTheme: _messageTheme,
|
||||||
|
// );
|
||||||
|
// } else if (attachment.type == 'image') {
|
||||||
|
// attachmentWidget = ImageAttachment(
|
||||||
|
// attachment: attachment,
|
||||||
|
// messageTheme: _messageTheme,
|
||||||
|
// );
|
||||||
|
// } else if (attachment.type == 'file') {
|
||||||
|
// attachmentWidget = FileAttachment(
|
||||||
|
// attachment: attachment,
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
if (attachmentWidget != null) {
|
if (attachmentWidget != null) {
|
||||||
return _buildAttachment(
|
return _buildAttachment(
|
||||||
|
|||||||
Reference in New Issue
Block a user