diff --git a/lib/blip_ds.dart b/lib/blip_ds.dart index b5b084ab..c71e2b3c 100644 --- a/lib/blip_ds.dart +++ b/lib/blip_ds.dart @@ -85,12 +85,16 @@ export 'src/widgets/chat/audio/ds_audio_message_bubble.widget.dart' show DSAudioMessageBubble; export 'src/widgets/chat/audio/ds_audio_player.widget.dart' show DSAudioPlayer; export 'src/widgets/chat/ds_carrousel.widget.dart' show DSCarrousel; +export 'src/widgets/chat/ds_contact_message_bubble.widget.dart' + show DSContactMessageBubble; export 'src/widgets/chat/ds_delivery_report_icon.widget.dart' show DSDeliveryReportIcon; export 'src/widgets/chat/ds_file_message_bubble.widget.dart' show DSFileMessageBubble; export 'src/widgets/chat/ds_image_message_bubble.widget.dart' show DSImageMessageBubble; +export 'src/widgets/chat/ds_location_message_bubble.widget.dart' + show DSLocationMessageBubble; export 'src/widgets/chat/ds_message_bubble.widget.dart' show DSMessageBubble; export 'src/widgets/chat/ds_message_bubble_detail.widget.dart' show DSMessageBubbleDetail; @@ -148,4 +152,3 @@ export 'src/widgets/utils/ds_group_card.widget.dart' show DSGroupCard; export 'src/widgets/utils/ds_header.widget.dart' show DSHeader; export 'src/widgets/utils/ds_progress_bar.widget.dart' show DSProgressBar; export 'src/widgets/utils/ds_user_avatar.widget.dart' show DSUserAvatar; -export 'src/widgets/chat/ds_contact_message_bubble.widget.dart' show DSContactMessageBubble; \ No newline at end of file diff --git a/lib/src/utils/ds_message_content_type.util.dart b/lib/src/utils/ds_message_content_type.util.dart index 11e09aef..c2f4b135 100644 --- a/lib/src/utils/ds_message_content_type.util.dart +++ b/lib/src/utils/ds_message_content_type.util.dart @@ -9,4 +9,5 @@ abstract class DSMessageContentType { static const String collection = 'application/vnd.lime.collection+json'; static const String ticket = 'application/vnd.iris.ticket+json'; static const String contact = 'application/vnd.lime.contact+json'; + static const String location = 'application/vnd.lime.location+json'; } diff --git a/lib/src/widgets/chat/ds_location_message_bubble.widget.dart b/lib/src/widgets/chat/ds_location_message_bubble.widget.dart new file mode 100644 index 00000000..28c8b3dd --- /dev/null +++ b/lib/src/widgets/chat/ds_location_message_bubble.widget.dart @@ -0,0 +1,104 @@ +import 'package:flutter/material.dart'; +import 'package:map_launcher/map_launcher.dart'; + +import '../../enums/ds_align.enum.dart'; +import '../../models/ds_message_bubble_style.model.dart'; +import '../../themes/colors/ds_colors.theme.dart'; +import '../animations/ds_spinner_loading.widget.dart'; +import '../texts/ds_body_text.widget.dart'; +import '../utils/ds_cached_network_image_view.widget.dart'; +import 'ds_message_bubble.widget.dart'; + +class DSLocationMessageBubble extends StatelessWidget { + final DSAlign align; + final DSMessageBubbleStyle style; + final String? title; + final double latitude; + final double longitude; + + DSLocationMessageBubble({ + super.key, + required this.align, + required this.latitude, + required this.longitude, + DSMessageBubbleStyle? style, + this.title, + }) : style = style ?? DSMessageBubbleStyle(); + + final appKey = 'AIzaSyAlC3a3DZZBscR0QIbQpee13Op9Y05m_wc'; + + @override + Widget build(BuildContext context) { + final foregroundColor = style.isLightBubbleBackground(align) + ? DSColors.neutralDarkCity + : DSColors.neutralLightSnow; + + return GestureDetector( + onTap: () async { + final availableMaps = await MapLauncher.installedMaps; + + await availableMaps.first.showMarker( + coords: Coords(latitude, longitude), + title: "Ocean Beach", + ); + }, + child: DSMessageBubble( + shouldUseDefaultSize: true, + defaultMaxSize: 240.0, + defaultMinSize: 240.0, + padding: EdgeInsets.zero, + align: align, + style: style, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + DSCachedNetworkImageView( + url: + 'https://maps.googleapis.com/maps/api/staticmap?&size=360x360&markers=$latitude,$longitude&key=$appKey', + placeholder: (_, __) => _buildLoading(), + align: align, + style: style, + ), + if (title?.isNotEmpty ?? false) + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0, + vertical: 8.0, + ), + child: Align( + alignment: Alignment.topLeft, + child: DSBodyText( + title!, + color: foregroundColor, + isSelectable: true, + overflow: TextOverflow.visible, + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildLoading() => Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + vertical: 8.0, + ), + child: Center( + child: DSSpinnerLoading( + color: style.isLightBubbleBackground(align) + ? DSColors.primaryNight + : DSColors.neutralLightSnow, + size: 32.0, + lineWidth: 4.0, + ), + ), + ), + ], + ); +} diff --git a/lib/src/widgets/utils/ds_card.widget.dart b/lib/src/widgets/utils/ds_card.widget.dart index 780e1e79..29c85f87 100644 --- a/lib/src/widgets/utils/ds_card.widget.dart +++ b/lib/src/widgets/utils/ds_card.widget.dart @@ -12,6 +12,7 @@ import '../chat/ds_carrousel.widget.dart'; import '../chat/ds_contact_message_bubble.widget.dart'; import '../chat/ds_file_message_bubble.widget.dart'; import '../chat/ds_image_message_bubble.widget.dart'; +import '../chat/ds_location_message_bubble.widget.dart'; import '../chat/ds_quick_reply.widget.dart'; import '../chat/ds_text_message_bubble.widget.dart'; import '../chat/ds_unsupported_content_message_bubble.widget.dart'; @@ -95,6 +96,14 @@ class DSCard extends StatelessWidget { style: style, ); + case DSMessageContentType.location: + return DSLocationMessageBubble( + title: content['text'], + latitude: content['latitude'], + longitude: content['longitude'], + align: align, + style: style, + ); case DSMessageContentType.ticket: return DSTicketMessage( messageType: DSTicketMessageType.forwardedTicket, diff --git a/pubspec.yaml b/pubspec.yaml index 1a163838..8468b35f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: intl_phone_number_input: ^0.7.3+1 mask_text_input_formatter: ^2.4.0 dotted_border: ^2.0.0+3 + map_launcher: ^2.5.0+1 dev_dependencies: flutter_test: diff --git a/sample/lib/widgets/showcase/sample_message_bubble.showcase.dart b/sample/lib/widgets/showcase/sample_message_bubble.showcase.dart index 66dd55f0..f2577fe1 100644 --- a/sample/lib/widgets/showcase/sample_message_bubble.showcase.dart +++ b/sample/lib/widgets/showcase/sample_message_bubble.showcase.dart @@ -287,6 +287,11 @@ class SampleMessageBubbleShowcase extends StatelessWidget { DSSurveyMessageBubble( align: DSAlign.center, ), + DSLocationMessageBubble( + align: DSAlign.left, + latitude: 47.5951518, + longitude: 122.3316393, + ), ], ), );