From 789d91a7635e49e561e88cbad00ddccd4e359e3b Mon Sep 17 00:00:00 2001 From: gilice <104317939+gilice@users.noreply.github.com> Date: Wed, 23 Aug 2023 20:15:30 +0200 Subject: [PATCH] feat/ChatListItem: small changes - extract hasNotifications to a variable this is more clear and potentially faster as we don't compute `notifications > 0` multiple times - make a text style const --- lib/pages/chat_list/chat_list_item.dart | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index 1ea3fdd70..9475b8a48 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -154,6 +154,7 @@ class ChatListItem extends StatelessWidget { ? 20.0 : 14.0 : 0.0; + final hasNotifications = room.notificationCount > 0; final displayname = room.getLocalizedDisplayname( MatrixLocals(L10n.of(context)!), ); @@ -197,9 +198,9 @@ class ChatListItem extends StatelessWidget { maxLines: 1, overflow: TextOverflow.ellipsis, softWrap: false, - style: TextStyle( - fontWeight: unread ? FontWeight.bold : null, - ), + style: unread + ? const TextStyle(fontWeight: FontWeight.bold) + : null, ), ), if (isMuted) @@ -213,7 +214,7 @@ class ChatListItem extends StatelessWidget { if (room.isFavourite || room.membership == Membership.invite) Padding( padding: EdgeInsets.only( - right: room.notificationCount > 0 ? 4.0 : 0.0, + right: hasNotifications ? 4.0 : 0.0, ), child: Icon( Icons.push_pin, @@ -325,9 +326,7 @@ class ChatListItem extends StatelessWidget { curve: FluffyThemes.animationCurve, padding: const EdgeInsets.symmetric(horizontal: 7), height: unreadBubbleSize, - width: room.notificationCount == 0 && - !unread && - !room.hasNewMessages + width: !hasNotifications && !unread && !room.hasNewMessages ? 0 : (unreadBubbleSize - 9) * room.notificationCount.toString().length + @@ -336,19 +335,19 @@ class ChatListItem extends StatelessWidget { color: room.highlightCount > 0 || room.membership == Membership.invite ? Colors.red - : room.notificationCount > 0 || room.markedUnread + : hasNotifications || room.markedUnread ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.primaryContainer, borderRadius: BorderRadius.circular(AppConfig.borderRadius), ), child: Center( - child: room.notificationCount > 0 + child: hasNotifications ? Text( room.notificationCount.toString(), style: TextStyle( color: room.highlightCount > 0 ? Colors.white - : room.notificationCount > 0 + : hasNotifications ? Theme.of(context).colorScheme.onPrimary : Theme.of(context) .colorScheme