aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/chat_bubble.dart
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-05-22 09:00:45 -0600
committerIván Ávalos <avalos@disroot.org>2023-05-22 09:00:45 -0600
commitf0e45a5a510d2b4693580179645bd0bb0b352f86 (patch)
tree1de8c7235e5dba68898a1ac33f5d420a18ac2fff /lib/widgets/chat_bubble.dart
parent786267d0ebb337ad5b4f1e528fdd4c23731e0606 (diff)
downloadlinkchat-f0e45a5a510d2b4693580179645bd0bb0b352f86.tar.gz
linkchat-f0e45a5a510d2b4693580179645bd0bb0b352f86.tar.bz2
linkchat-f0e45a5a510d2b4693580179645bd0bb0b352f86.zip
Soporte y restricción para links
Diffstat (limited to 'lib/widgets/chat_bubble.dart')
-rw-r--r--lib/widgets/chat_bubble.dart105
1 files changed, 91 insertions, 14 deletions
diff --git a/lib/widgets/chat_bubble.dart b/lib/widgets/chat_bubble.dart
index aaac93d..7c2e16c 100644
--- a/lib/widgets/chat_bubble.dart
+++ b/lib/widgets/chat_bubble.dart
@@ -1,14 +1,16 @@
import 'package:custom_clippers/custom_clippers.dart';
import 'package:flutter/material.dart';
+import 'package:linkchat/models/message.dart';
+import 'package:url_launcher/link.dart';
enum ChatBubbleAlignment { start, end }
class ChatBubble extends StatelessWidget {
- final String text;
+ final Message message;
final ChatBubbleAlignment alignment;
const ChatBubble(
- this.text, {
+ this.message, {
super.key,
required this.alignment,
});
@@ -19,17 +21,17 @@ class ChatBubble extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
alignment == ChatBubbleAlignment.start
- ? BubbleLeft(text)
- : BubbleRight(text),
+ ? BubbleLeft(message)
+ : BubbleRight(message),
],
);
}
}
class BubbleLeft extends StatelessWidget {
- final String text;
+ final Message message;
- const BubbleLeft(this.text, {super.key});
+ const BubbleLeft(this.message, {super.key});
@override
Widget build(BuildContext context) {
@@ -42,9 +44,20 @@ class BubbleLeft extends StatelessWidget {
decoration: const BoxDecoration(
color: Color(0xFFE1E1E2),
),
- child: Text(
- text,
- style: const TextStyle(fontSize: 15, color: Colors.black),
+ child: Column(
+ children: [
+ LinkPreview(message),
+ Link(
+ uri: Uri.parse(message.messageText),
+ builder: (context, followLink) => TextButton(
+ onPressed: followLink,
+ child: Text(
+ message.messageText,
+ style: const TextStyle(color: Colors.blue),
+ ),
+ ),
+ ),
+ ],
),
),
),
@@ -53,9 +66,9 @@ class BubbleLeft extends StatelessWidget {
}
class BubbleRight extends StatelessWidget {
- final String text;
+ final Message message;
- const BubbleRight(this.text, {super.key});
+ const BubbleRight(this.message, {super.key});
@override
Widget build(BuildContext context) {
@@ -71,9 +84,21 @@ class BubbleRight extends StatelessWidget {
decoration: const BoxDecoration(
color: Color(0xFF113753),
),
- child: Text(
- text,
- style: const TextStyle(fontSize: 15, color: Colors.white),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ LinkPreview(message),
+ Link(
+ uri: Uri.parse(message.messageText),
+ builder: (context, followLink) => TextButton(
+ onPressed: followLink,
+ child: Text(
+ message.messageText,
+ style: const TextStyle(color: Colors.blue),
+ ),
+ ),
+ ),
+ ],
),
),
),
@@ -81,3 +106,55 @@ class BubbleRight extends StatelessWidget {
);
}
}
+
+class LinkPreview extends StatelessWidget {
+ final Message message;
+ const LinkPreview(this.message, {super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return (message.linkTitle != null ||
+ message.linkDescription != null ||
+ message.linkPhotoURL != null)
+ ? Padding(
+ padding: const EdgeInsets.only(bottom: 8.0),
+ child: Card(
+ clipBehavior: Clip.antiAliasWithSaveLayer,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ message.linkPhotoURL != null
+ ? FadeInImage(
+ placeholder: const AssetImage('assets/loading.gif'),
+ image: NetworkImage(message.linkPhotoURL!),
+ imageErrorBuilder: (context, error, stackTrace) =>
+ const SizedBox.shrink(),
+ fit: BoxFit.fill,
+ )
+ : const SizedBox.shrink(),
+ message.linkTitle != null
+ ? Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: Text(
+ message.linkTitle!,
+ style: Theme.of(context)
+ .textTheme
+ .bodyLarge!
+ .copyWith(fontWeight: FontWeight.bold),
+ ),
+ )
+ : const SizedBox.shrink(),
+ message.linkDescription != null
+ ? Padding(
+ padding:
+ const EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 8.0),
+ child: Text(message.linkDescription!),
+ )
+ : const SizedBox.shrink(),
+ ],
+ ),
+ ),
+ )
+ : const SizedBox.shrink();
+ }
+}