From 1927a632e08a0c65d712ed91045e49b33c5c2ecd Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Wed, 6 Jan 2021 17:00:56 +0530 Subject: [PATCH] fix: fixed null sometimes popping up --- lib/src/channel_preview.dart | 12 ++++++++---- lib/src/message_search_item.dart | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart index 122e6a87..1f64f16f 100644 --- a/lib/src/channel_preview.dart +++ b/lib/src/channel_preview.dart @@ -269,14 +269,18 @@ class ChannelPreview extends StatelessWidget { var textList = text.split(' '); List resList = []; for (var e in textList) { - if (mentions.any((element) => '@${element.name}' == e)) { + if (mentions != null && + mentions.isNotEmpty && + mentions.any((element) => '@${element.name}' == e)) { resList.add(TextSpan( text: '$e ', style: mentionsTextStyle, )); - } else if (attachments - .where((e) => e.title != null) - .any((element) => element.title == e)) { + } else if (attachments != null && + attachments.isNotEmpty && + attachments + .where((e) => e.title != null) + .any((element) => element.title == e)) { resList.add(TextSpan( text: '$e ', style: normalTextStyle.copyWith(fontStyle: FontStyle.italic), diff --git a/lib/src/message_search_item.dart b/lib/src/message_search_item.dart index 62e5f29d..35cec093 100644 --- a/lib/src/message_search_item.dart +++ b/lib/src/message_search_item.dart @@ -165,14 +165,18 @@ class MessageSearchItem extends StatelessWidget { var textList = text.split(' '); List resList = []; for (var e in textList) { - if (mentions.any((element) => '@${element.name}' == e)) { + if (mentions != null && + mentions.isNotEmpty && + mentions.any((element) => '@${element.name}' == e)) { resList.add(TextSpan( text: '$e ', style: mentionsTextStyle, )); - } else if (attachments - .where((e) => e.title != null) - .any((element) => element.title == e)) { + } else if (attachments != null && + attachments.isNotEmpty && + attachments + .where((e) => e.title != null) + .any((element) => element.title == e)) { resList.add(TextSpan( text: '$e ', style: normalTextStyle.copyWith(fontStyle: FontStyle.italic),