From b6d7ff9f07bd17e9934181f0507261fbb76f4b52 Mon Sep 17 00:00:00 2001 From: RaulRodrigo06 Date: Tue, 3 Oct 2023 18:30:23 -0300 Subject: [PATCH 1/4] feat: adding image and text plain to reply message --- .../utils/ds_message_content_type.util.dart | 1 + .../chat/ds_reply_message_bubble.widget.dart | 98 +++++++++++++++++++ .../ds_cached_network_image_view.widget.dart | 2 +- lib/src/widgets/utils/ds_card.widget.dart | 41 +++++++- 4 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 lib/src/widgets/chat/ds_reply_message_bubble.widget.dart diff --git a/lib/src/utils/ds_message_content_type.util.dart b/lib/src/utils/ds_message_content_type.util.dart index cee5c03d..eb5d4ab9 100644 --- a/lib/src/utils/ds_message_content_type.util.dart +++ b/lib/src/utils/ds_message_content_type.util.dart @@ -12,4 +12,5 @@ abstract class DSMessageContentType { static const String input = 'application/vnd.lime.input+json'; static const String location = 'application/vnd.lime.location+json'; static const String applicationJson = 'application/json'; + static const String reply = 'application/vnd.lime.reply+json'; } diff --git a/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart b/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart new file mode 100644 index 00000000..26e4c6d9 --- /dev/null +++ b/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; + +import '../../enums/ds_align.enum.dart'; +import '../../enums/ds_border_radius.enum.dart'; +import '../../models/ds_message_bubble_style.model.dart'; +import '../../themes/colors/ds_colors.theme.dart'; +import '../../utils/ds_linkify.util.dart'; +import 'ds_message_bubble.widget.dart'; +import 'ds_show_more_text.widget.dart'; +import 'ds_url_preview.widget.dart'; + +class DSReplyMessageBubble extends StatefulWidget { + final String text; + final DSAlign align; + final bool hasSpacer; + final List borderRadius; + final DSMessageBubbleStyle style; + + DSReplyMessageBubble({ + Key? key, + required this.text, + required this.align, + this.borderRadius = const [DSBorderRadius.all], + this.hasSpacer = true, + DSMessageBubbleStyle? style, + }) : style = style ?? DSMessageBubbleStyle(), + super(key: key); + + @override + State createState() => _DSTextMessageBubbleState(); +} + +class _DSTextMessageBubbleState extends State { + late final bool _isLightBubbleBackground; + + @override + void initState() { + super.initState(); + + _isLightBubbleBackground = + widget.style.isLightBubbleBackground(widget.align); + } + + final EdgeInsets _defaultBodyPadding = const EdgeInsets.symmetric( + vertical: 8.0, + horizontal: 16.0, + ); + + @override + Widget build(BuildContext context) { + return DSMessageBubble( + align: widget.align, + borderRadius: widget.borderRadius, + padding: EdgeInsets.zero, + style: widget.style, + hasSpacer: widget.hasSpacer, + child: _buildText(), + ); + } + + Widget _buildText() { + final foregroundColor = widget.style.isLightBubbleBackground(widget.align) + ? DSColors.neutralDarkCity + : DSColors.neutralLightSnow; + + final url = DSLinkify.getFirstUrlFromText(widget.text); + + return LayoutBuilder( + builder: (_, constraints) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (url.toString().isNotEmpty) + DSUrlPreview( + url: url, + foregroundColor: foregroundColor, + backgroundColor: _isLightBubbleBackground + ? DSColors.neutralLightBox + : DSColors.neutralDarkDesk, + borderRadius: widget.borderRadius, + align: widget.align, + style: widget.style, + ), + Padding( + padding: _defaultBodyPadding, + child: DSShowMoreText( + align: widget.align, + style: widget.style, + text: widget.text, + maxWidth: constraints.maxWidth, + ), + ), + ], + ); + }, + ); + } +} diff --git a/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart b/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart index d1daca1a..c1ca55ed 100644 --- a/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart +++ b/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart @@ -56,7 +56,7 @@ class DSCachedNetworkImageView extends StatelessWidget { httpHeaders: shouldAuthenticate ? DSAuthService.httpHeaders : null, placeholder: placeholder, - errorWidget: (context, _, __) => _buildError(context), + errorWidget: (context, error, __) => _buildError(context), ), ); } diff --git a/lib/src/widgets/utils/ds_card.widget.dart b/lib/src/widgets/utils/ds_card.widget.dart index 6898ecb6..2de0f2f9 100644 --- a/lib/src/widgets/utils/ds_card.widget.dart +++ b/lib/src/widgets/utils/ds_card.widget.dart @@ -61,15 +61,19 @@ class DSCard extends StatelessWidget { @override Widget build(BuildContext context) { - return _resolveWidget(); + return _resolveWidget(messageType: type); } - Widget _resolveWidget() { - switch (type) { + Widget _resolveWidget({required String messageType}) { + switch (messageType) { case DSMessageContentType.textPlain: case DSMessageContentType.sensitive: return DSTextMessageBubble( - text: content is String ? content : '**********', + text: type == DSMessageContentType.reply + ? content['replied']['value'] + : content is String + ? content + : '**********', align: align, borderRadius: borderRadius, style: style, @@ -78,6 +82,9 @@ class DSCard extends StatelessWidget { case DSMessageContentType.contact: return _buildContact(); + case DSMessageContentType.reply: + return _resolveWidget(messageType: content['replied']['type']); + case DSMessageContentType.mediaLink: return _buildMediaLink(); @@ -145,6 +152,26 @@ class DSCard extends StatelessWidget { } } + // Widget _buildReply() { + // switch (content['replied']['type']) { + // case DSMessageContentType.textPlain: + // return DSTextMessageBubble( + // text: content['replied']['value'], + // align: align, + // borderRadius: borderRadius, + // style: style, + // ); + + // default: + // return DSTextMessageBubble( + // text: content['replied']['value'], + // align: align, + // borderRadius: borderRadius, + // style: style, + // ); + // } + // } + Widget _buildDocumentSelect() { final documentSelectModel = DSDocumentSelectModel.fromJson(content); @@ -219,7 +246,11 @@ class DSCard extends StatelessWidget { } Widget _buildMediaLink() { - final media = DSMediaLink.fromJson(content); + final media = DSMediaLink.fromJson( + type == DSMessageContentType.reply + ? content['replied']['value'] + : content, + ); final size = media.size ?? 0; final shouldAuthenticate = From 80ce1763e41eb8316c697287fcc23a06062ee983 Mon Sep 17 00:00:00 2001 From: RaulRodrigo06 Date: Wed, 4 Oct 2023 18:01:36 -0300 Subject: [PATCH 2/4] chore: deleting unused file --- .../chat/ds_reply_message_bubble.widget.dart | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 lib/src/widgets/chat/ds_reply_message_bubble.widget.dart diff --git a/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart b/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart deleted file mode 100644 index 26e4c6d9..00000000 --- a/lib/src/widgets/chat/ds_reply_message_bubble.widget.dart +++ /dev/null @@ -1,98 +0,0 @@ -import 'package:flutter/material.dart'; - -import '../../enums/ds_align.enum.dart'; -import '../../enums/ds_border_radius.enum.dart'; -import '../../models/ds_message_bubble_style.model.dart'; -import '../../themes/colors/ds_colors.theme.dart'; -import '../../utils/ds_linkify.util.dart'; -import 'ds_message_bubble.widget.dart'; -import 'ds_show_more_text.widget.dart'; -import 'ds_url_preview.widget.dart'; - -class DSReplyMessageBubble extends StatefulWidget { - final String text; - final DSAlign align; - final bool hasSpacer; - final List borderRadius; - final DSMessageBubbleStyle style; - - DSReplyMessageBubble({ - Key? key, - required this.text, - required this.align, - this.borderRadius = const [DSBorderRadius.all], - this.hasSpacer = true, - DSMessageBubbleStyle? style, - }) : style = style ?? DSMessageBubbleStyle(), - super(key: key); - - @override - State createState() => _DSTextMessageBubbleState(); -} - -class _DSTextMessageBubbleState extends State { - late final bool _isLightBubbleBackground; - - @override - void initState() { - super.initState(); - - _isLightBubbleBackground = - widget.style.isLightBubbleBackground(widget.align); - } - - final EdgeInsets _defaultBodyPadding = const EdgeInsets.symmetric( - vertical: 8.0, - horizontal: 16.0, - ); - - @override - Widget build(BuildContext context) { - return DSMessageBubble( - align: widget.align, - borderRadius: widget.borderRadius, - padding: EdgeInsets.zero, - style: widget.style, - hasSpacer: widget.hasSpacer, - child: _buildText(), - ); - } - - Widget _buildText() { - final foregroundColor = widget.style.isLightBubbleBackground(widget.align) - ? DSColors.neutralDarkCity - : DSColors.neutralLightSnow; - - final url = DSLinkify.getFirstUrlFromText(widget.text); - - return LayoutBuilder( - builder: (_, constraints) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (url.toString().isNotEmpty) - DSUrlPreview( - url: url, - foregroundColor: foregroundColor, - backgroundColor: _isLightBubbleBackground - ? DSColors.neutralLightBox - : DSColors.neutralDarkDesk, - borderRadius: widget.borderRadius, - align: widget.align, - style: widget.style, - ), - Padding( - padding: _defaultBodyPadding, - child: DSShowMoreText( - align: widget.align, - style: widget.style, - text: widget.text, - maxWidth: constraints.maxWidth, - ), - ), - ], - ); - }, - ); - } -} From ca6094dcdb07a2018a839a5b5847812867972ada Mon Sep 17 00:00:00 2001 From: RaulRodrigo06 Date: Mon, 9 Oct 2023 15:37:27 -0300 Subject: [PATCH 3/4] fix: improve code --- .../ds_cached_network_image_view.widget.dart | 2 +- lib/src/widgets/utils/ds_card.widget.dart | 43 +++++-------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart b/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart index c1ca55ed..d1daca1a 100644 --- a/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart +++ b/lib/src/widgets/utils/ds_cached_network_image_view.widget.dart @@ -56,7 +56,7 @@ class DSCachedNetworkImageView extends StatelessWidget { httpHeaders: shouldAuthenticate ? DSAuthService.httpHeaders : null, placeholder: placeholder, - errorWidget: (context, error, __) => _buildError(context), + errorWidget: (context, _, __) => _buildError(context), ), ); } diff --git a/lib/src/widgets/utils/ds_card.widget.dart b/lib/src/widgets/utils/ds_card.widget.dart index 2de0f2f9..e5a952ba 100644 --- a/lib/src/widgets/utils/ds_card.widget.dart +++ b/lib/src/widgets/utils/ds_card.widget.dart @@ -61,19 +61,15 @@ class DSCard extends StatelessWidget { @override Widget build(BuildContext context) { - return _resolveWidget(messageType: type); + return _resolveWidget(); } - Widget _resolveWidget({required String messageType}) { - switch (messageType) { + Widget _resolveWidget() { + switch (type) { case DSMessageContentType.textPlain: case DSMessageContentType.sensitive: return DSTextMessageBubble( - text: type == DSMessageContentType.reply - ? content['replied']['value'] - : content is String - ? content - : '**********', + text: content is String ? content : '**********', align: align, borderRadius: borderRadius, style: style, @@ -83,7 +79,12 @@ class DSCard extends StatelessWidget { return _buildContact(); case DSMessageContentType.reply: - return _resolveWidget(messageType: content['replied']['type']); + return DSCard( + type: content['replied']['type'], + content: content['replied']['value'], + align: align, + borderRadius: borderRadius, + ); case DSMessageContentType.mediaLink: return _buildMediaLink(); @@ -152,26 +153,6 @@ class DSCard extends StatelessWidget { } } - // Widget _buildReply() { - // switch (content['replied']['type']) { - // case DSMessageContentType.textPlain: - // return DSTextMessageBubble( - // text: content['replied']['value'], - // align: align, - // borderRadius: borderRadius, - // style: style, - // ); - - // default: - // return DSTextMessageBubble( - // text: content['replied']['value'], - // align: align, - // borderRadius: borderRadius, - // style: style, - // ); - // } - // } - Widget _buildDocumentSelect() { final documentSelectModel = DSDocumentSelectModel.fromJson(content); @@ -247,9 +228,7 @@ class DSCard extends StatelessWidget { Widget _buildMediaLink() { final media = DSMediaLink.fromJson( - type == DSMessageContentType.reply - ? content['replied']['value'] - : content, + content, ); final size = media.size ?? 0; From 90931795a32cf9a796390bf8bc007666777a57e0 Mon Sep 17 00:00:00 2001 From: RaulRodrigo06 Date: Tue, 10 Oct 2023 15:55:23 -0300 Subject: [PATCH 4/4] feat: add all parameters on dscard --- lib/src/widgets/utils/ds_card.widget.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/src/widgets/utils/ds_card.widget.dart b/lib/src/widgets/utils/ds_card.widget.dart index e5a952ba..596ce460 100644 --- a/lib/src/widgets/utils/ds_card.widget.dart +++ b/lib/src/widgets/utils/ds_card.widget.dart @@ -84,6 +84,13 @@ class DSCard extends StatelessWidget { content: content['replied']['value'], align: align, borderRadius: borderRadius, + status: status, + onSelected: onSelected, + avatarConfig: avatarConfig, + style: style, + onOpenLink: onOpenLink, + messageId: messageId, + customer: customer, ); case DSMessageContentType.mediaLink: