refactor: optimize ChatsDrawer for performance and smooth scrolling

- Added cacheExtent to the ListView in ChatsDrawer for improved scrolling smoothness.
- Updated activeConversationProvider selection to only rebuild tiles when their selected state changes, enhancing performance.
- Replaced Padding with RepaintBoundary to optimize rendering during drag operations.
- Changed clipBehavior to Clip.hardEdge for better performance in avatar rendering.
This commit is contained in:
cogwheel0
2025-10-10 13:12:26 +05:30
parent 778116e258
commit 9fff4d49ea

View File

@@ -108,6 +108,8 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
key: const PageStorageKey<String>('chats_drawer_scroll'),
controller: _listController,
physics: const AlwaysScrollableScrollPhysics(),
// Precache a bit ahead for perceived smoothness when scrolling.
cacheExtent: 800,
padding: padding,
children: children,
),
@@ -1068,7 +1070,10 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
}
Widget _buildTileFor(dynamic conv, {bool inFolder = false}) {
final isActive = ref.watch(activeConversationProvider)?.id == conv.id;
// Only rebuild this tile when its own selected state changes.
final isActive = ref.watch(
activeConversationProvider.select((c) => c?.id == conv.id),
);
final title = conv.title?.isEmpty == true ? 'Chat' : (conv.title ?? 'Chat');
final theme = context.conduitTheme;
final bool isLoadingSelected =
@@ -1124,7 +1129,8 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
},
);
return Padding(
return RepaintBoundary(
child: Padding(
padding: EdgeInsets.only(
bottom: Spacing.xs,
left: inFolder ? Spacing.md : 0,
@@ -1157,6 +1163,7 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
}),
child: tile,
),
),
);
}
@@ -1375,7 +1382,9 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
width: BorderWidth.thin,
),
),
clipBehavior: Clip.antiAlias,
// Hard-edge clipping is cheaper than anti-aliased clipping
// and sufficient for avatar squares with rounded corners.
clipBehavior: Clip.hardEdge,
child: UserAvatar(
size: 36,
imageUrl: avatarUrl,