mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-17 08:55:12 +00:00
refactor: Precache theme and directchatmatrixid to improve performance in chat list item
This commit is contained in:
parent
fb54548e5c
commit
6a220ffb4b
1 changed files with 23 additions and 28 deletions
|
@ -12,7 +12,6 @@ import 'package:fluffychat/widgets/hover_builder.dart';
|
||||||
import '../../config/themes.dart';
|
import '../../config/themes.dart';
|
||||||
import '../../utils/date_time_extension.dart';
|
import '../../utils/date_time_extension.dart';
|
||||||
import '../../widgets/avatar.dart';
|
import '../../widgets/avatar.dart';
|
||||||
import '../../widgets/matrix.dart';
|
|
||||||
|
|
||||||
enum ArchivedRoomAction { delete, rejoin }
|
enum ArchivedRoomAction { delete, rejoin }
|
||||||
|
|
||||||
|
@ -65,8 +64,11 @@ class ChatListItem extends StatelessWidget {
|
||||||
final isMuted = room.pushRuleState != PushRuleState.notify;
|
final isMuted = room.pushRuleState != PushRuleState.notify;
|
||||||
final typingText = room.getLocalizedTypingText(context);
|
final typingText = room.getLocalizedTypingText(context);
|
||||||
final lastEvent = room.lastEvent;
|
final lastEvent = room.lastEvent;
|
||||||
final ownMessage = lastEvent?.senderId == Matrix.of(context).client.userID;
|
final ownMessage = lastEvent?.senderId == room.client.userID;
|
||||||
final unread = room.isUnread || room.membership == Membership.invite;
|
final unread = room.isUnread || room.membership == Membership.invite;
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final directChatMatrixId = room.directChatMatrixID;
|
||||||
|
final isDirectChat = directChatMatrixId != null;
|
||||||
final unreadBubbleSize = unread || room.hasNewMessages
|
final unreadBubbleSize = unread || room.hasNewMessages
|
||||||
? room.notificationCount > 0
|
? room.notificationCount > 0
|
||||||
? 20.0
|
? 20.0
|
||||||
|
@ -74,9 +76,9 @@ class ChatListItem extends StatelessWidget {
|
||||||
: 0.0;
|
: 0.0;
|
||||||
final hasNotifications = room.notificationCount > 0;
|
final hasNotifications = room.notificationCount > 0;
|
||||||
final backgroundColor = selected
|
final backgroundColor = selected
|
||||||
? Theme.of(context).colorScheme.primaryContainer
|
? theme.colorScheme.primaryContainer
|
||||||
: activeChat
|
: activeChat
|
||||||
? Theme.of(context).colorScheme.secondaryContainer
|
? theme.colorScheme.secondaryContainer
|
||||||
: null;
|
: null;
|
||||||
final displayname = room.getLocalizedDisplayname(
|
final displayname = room.getLocalizedDisplayname(
|
||||||
MatrixLocals(L10n.of(context)!),
|
MatrixLocals(L10n.of(context)!),
|
||||||
|
@ -108,7 +110,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
child: Avatar(
|
child: Avatar(
|
||||||
mxContent: room.avatar,
|
mxContent: room.avatar,
|
||||||
name: displayname,
|
name: displayname,
|
||||||
presenceUserId: room.directChatMatrixID,
|
presenceUserId: directChatMatrixId,
|
||||||
presenceBackgroundColor: backgroundColor,
|
presenceBackgroundColor: backgroundColor,
|
||||||
onTap: onLongPress,
|
onTap: onLongPress,
|
||||||
),
|
),
|
||||||
|
@ -164,7 +166,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.push_pin,
|
Icons.push_pin,
|
||||||
size: 16,
|
size: 16,
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: theme.colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (lastEvent != null && room.membership != Membership.invite)
|
if (lastEvent != null && room.membership != Membership.invite)
|
||||||
|
@ -175,8 +177,8 @@ class ChatListItem extends StatelessWidget {
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: unread
|
color: unread
|
||||||
? Theme.of(context).colorScheme.secondary
|
? theme.colorScheme.secondary
|
||||||
: Theme.of(context).textTheme.bodyMedium!.color,
|
: theme.textTheme.bodyMedium!.color,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -204,7 +206,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
padding: const EdgeInsets.only(right: 4),
|
padding: const EdgeInsets.only(right: 4),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.edit_outlined,
|
Icons.edit_outlined,
|
||||||
color: Theme.of(context).colorScheme.secondary,
|
color: theme.colorScheme.secondary,
|
||||||
size: 14,
|
size: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -213,7 +215,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
? Text(
|
? Text(
|
||||||
typingText,
|
typingText,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: theme.colorScheme.primary,
|
||||||
),
|
),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
|
@ -225,15 +227,15 @@ class ChatListItem extends StatelessWidget {
|
||||||
hideEdit: true,
|
hideEdit: true,
|
||||||
plaintextBody: true,
|
plaintextBody: true,
|
||||||
removeMarkdown: true,
|
removeMarkdown: true,
|
||||||
withSenderNamePrefix: !room.isDirectChat ||
|
withSenderNamePrefix: !isDirectChat ||
|
||||||
room.directChatMatrixID !=
|
directChatMatrixId !=
|
||||||
room.lastEvent?.senderId,
|
room.lastEvent?.senderId,
|
||||||
) ??
|
) ??
|
||||||
Future.value(L10n.of(context)!.emptyChat),
|
Future.value(L10n.of(context)!.emptyChat),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return Text(
|
return Text(
|
||||||
room.membership == Membership.invite
|
room.membership == Membership.invite
|
||||||
? room.isDirectChat
|
? isDirectChat
|
||||||
? L10n.of(context)!.invitePrivateChat
|
? L10n.of(context)!.invitePrivateChat
|
||||||
: L10n.of(context)!.inviteGroupChat
|
: L10n.of(context)!.inviteGroupChat
|
||||||
: snapshot.data ??
|
: snapshot.data ??
|
||||||
|
@ -244,10 +246,9 @@ class ChatListItem extends StatelessWidget {
|
||||||
hideEdit: true,
|
hideEdit: true,
|
||||||
plaintextBody: true,
|
plaintextBody: true,
|
||||||
removeMarkdown: true,
|
removeMarkdown: true,
|
||||||
withSenderNamePrefix:
|
withSenderNamePrefix: !isDirectChat ||
|
||||||
!room.isDirectChat ||
|
directChatMatrixId !=
|
||||||
room.directChatMatrixID !=
|
room.lastEvent?.senderId,
|
||||||
room.lastEvent?.senderId,
|
|
||||||
) ??
|
) ??
|
||||||
L10n.of(context)!.emptyChat,
|
L10n.of(context)!.emptyChat,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
|
@ -257,9 +258,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
fontWeight: unread || room.hasNewMessages
|
fontWeight: unread || room.hasNewMessages
|
||||||
? FontWeight.bold
|
? FontWeight.bold
|
||||||
: null,
|
: null,
|
||||||
color: Theme.of(context)
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
.colorScheme
|
|
||||||
.onSurfaceVariant,
|
|
||||||
decoration: room.lastEvent?.redacted == true
|
decoration: room.lastEvent?.redacted == true
|
||||||
? TextDecoration.lineThrough
|
? TextDecoration.lineThrough
|
||||||
: null,
|
: null,
|
||||||
|
@ -284,8 +283,8 @@ class ChatListItem extends StatelessWidget {
|
||||||
room.membership == Membership.invite
|
room.membership == Membership.invite
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: hasNotifications || room.markedUnread
|
: hasNotifications || room.markedUnread
|
||||||
? Theme.of(context).colorScheme.primary
|
? theme.colorScheme.primary
|
||||||
: Theme.of(context).colorScheme.primaryContainer,
|
: theme.colorScheme.primaryContainer,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
BorderRadius.circular(AppConfig.borderRadius),
|
||||||
),
|
),
|
||||||
|
@ -297,12 +296,8 @@ class ChatListItem extends StatelessWidget {
|
||||||
color: room.highlightCount > 0
|
color: room.highlightCount > 0
|
||||||
? Colors.white
|
? Colors.white
|
||||||
: hasNotifications
|
: hasNotifications
|
||||||
? Theme.of(context)
|
? theme.colorScheme.onPrimary
|
||||||
.colorScheme
|
: theme.colorScheme.onPrimaryContainer,
|
||||||
.onPrimary
|
|
||||||
: Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.onPrimaryContainer,
|
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue