From 8d79274b0ceb856c6c8445fe92c3955a59468ef1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 5 Oct 2024 03:21:53 +0800 Subject: [PATCH] :bug: Fix dm channel display error with deleted user --- lib/screens/channel/channel_chat.dart | 7 ++++--- lib/widgets/channel/channel_list.dart | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/screens/channel/channel_chat.dart b/lib/screens/channel/channel_chat.dart index 262a11f..2d1697d 100644 --- a/lib/screens/channel/channel_chat.dart +++ b/lib/screens/channel/channel_chat.dart @@ -201,9 +201,10 @@ class _ChannelChatScreenState extends State String title = _channel?.name ?? 'loading'.tr; String? placeholder; - if (_channel?.type == 1) { - final otherside = - _channel!.members!.where((e) => e.account.id != _accountId).first; + final otherside = + _channel!.members!.where((e) => e.account.id != _accountId).firstOrNull; + + if (_channel?.type == 1 && otherside != null) { title = otherside.account.nick; placeholder = 'messageInputPlaceholder'.trParams( {'channel': '@${otherside.account.name}'}, diff --git a/lib/widgets/channel/channel_list.dart b/lib/widgets/channel/channel_list.dart index cd2b3b9..6ea43a1 100644 --- a/lib/widgets/channel/channel_list.dart +++ b/lib/widgets/channel/channel_list.dart @@ -132,10 +132,10 @@ class _ChannelListWidgetState extends State { ? const EdgeInsets.symmetric(horizontal: 20) : const EdgeInsets.symmetric(horizontal: 16); - if (item.type == 1) { - final otherside = - item.members!.where((e) => e.account.id != widget.selfId).first; + final otherside = + item.members!.where((e) => e.account.id != widget.selfId).firstOrNull; + if (item.type == 1 && otherside != null) { final avatar = AccountAvatar( content: otherside.account.avatar, radius: widget.isDense ? 12 : 20,