From 50e9cb38e9033a95ee5f27baffc4dc1ec5f645cc Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 20 Dec 2021 16:40:58 +0530 Subject: [PATCH] chore(ui): minor fixes Signed-off-by: xsahil03x --- .../lib/src/message_input/message_input.dart | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_input/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input/message_input.dart index 46072348..a28754d3 100644 --- a/packages/stream_chat_flutter/lib/src/message_input/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input/message_input.dart @@ -942,10 +942,15 @@ class MessageInputState extends State if (_lastSearchedContainsUrlText == value) return; _lastSearchedContainsUrlText = value; - final regex = - RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+'); - final matchedUrls = regex.allMatches(value); - if (matchedUrls.isEmpty) return; + final matchedUrls = + RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+') + .allMatches(value); + + // Reset the og attachment if the text doesn't contain any url + if (matchedUrls.isEmpty) { + setState(() => _ogAttachment = null); + return; + } final firstMatchedUrl = matchedUrls.first.group(0)!; @@ -955,19 +960,20 @@ class MessageInputState extends State final client = StreamChat.of(context).client; _enrichUrlOperation = CancelableOperation.fromFuture( - client.enrichUrl(firstMatchedUrl).then((ogAttachment) { + client.enrichUrl(firstMatchedUrl), + ).then( + (ogAttachment) { final attachment = Attachment.fromOGAttachment(ogAttachment); setState(() => _ogAttachment = attachment); - }).onError((error, stackTrace) { + }, + onError: (error, stackTrace) { // Reset the ogAttachment if there was an error setState(() => _ogAttachment = null); - if (error != null) { - widget.onError?.call(error, stackTrace); - } - }), + widget.onError?.call(error, stackTrace); + }, ); }, - const Duration(seconds: 1), + const Duration(milliseconds: 650), ); void _checkEmoji(String value, BuildContext context) {