mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 10:25:11 +00:00
refactor: Improve performance of chat list
This commit is contained in:
parent
3d362df80a
commit
3c85786c10
2 changed files with 24 additions and 31 deletions
|
@ -14,7 +14,6 @@ import 'package:fluffychat/pages/chat_list/status_msg_list.dart';
|
|||
import 'package:fluffychat/pages/chat_list/utils/on_chat_tap.dart';
|
||||
import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart';
|
||||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/stream_extension.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
||||
|
@ -43,7 +42,7 @@ class ChatListViewBody extends StatelessWidget {
|
|||
Theme.of(context).textTheme.bodyLarge!.color!.withAlpha(100);
|
||||
final subtitleColor =
|
||||
Theme.of(context).textTheme.bodyLarge!.color!.withAlpha(50);
|
||||
|
||||
final filter = controller.searchController.text.toLowerCase();
|
||||
return PageTransitionSwitcher(
|
||||
transitionBuilder: (
|
||||
Widget child,
|
||||
|
@ -239,35 +238,23 @@ class ChatListViewBody extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
if (client.prevBatch != null)
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int i) {
|
||||
if (!rooms[i]
|
||||
.getLocalizedDisplayname(
|
||||
MatrixLocals(L10n.of(context)!),
|
||||
)
|
||||
.toLowerCase()
|
||||
.contains(
|
||||
controller.searchController.text.toLowerCase(),
|
||||
)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final activeChat = controller.activeChat == rooms[i].id;
|
||||
return ChatListItem(
|
||||
rooms[i],
|
||||
key: Key('chat_list_item_${rooms[i].id}'),
|
||||
selected:
|
||||
controller.selectedRoomIds.contains(rooms[i].id),
|
||||
onTap: controller.selectMode == SelectMode.select
|
||||
? () => controller.toggleSelection(rooms[i].id)
|
||||
: () => onChatTap(rooms[i], context),
|
||||
onLongPress: () =>
|
||||
controller.toggleSelection(rooms[i].id),
|
||||
activeChat: activeChat,
|
||||
);
|
||||
},
|
||||
childCount: rooms.length,
|
||||
),
|
||||
SliverList.builder(
|
||||
itemCount: rooms.length,
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
return ChatListItem(
|
||||
rooms[i],
|
||||
key: Key('chat_list_item_${rooms[i].id}'),
|
||||
filter: filter,
|
||||
selected:
|
||||
controller.selectedRoomIds.contains(rooms[i].id),
|
||||
onTap: controller.selectMode == SelectMode.select
|
||||
? () => controller.toggleSelection(rooms[i].id)
|
||||
: () => onChatTap(rooms[i], context),
|
||||
onLongPress: () =>
|
||||
controller.toggleSelection(rooms[i].id),
|
||||
activeChat: controller.activeChat == rooms[i].id,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -22,6 +22,7 @@ class ChatListItem extends StatelessWidget {
|
|||
final void Function()? onLongPress;
|
||||
final void Function()? onForget;
|
||||
final void Function() onTap;
|
||||
final String? filter;
|
||||
|
||||
const ChatListItem(
|
||||
this.room, {
|
||||
|
@ -30,6 +31,7 @@ class ChatListItem extends StatelessWidget {
|
|||
required this.onTap,
|
||||
this.onLongPress,
|
||||
this.onForget,
|
||||
this.filter,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -83,6 +85,10 @@ class ChatListItem extends StatelessWidget {
|
|||
final displayname = room.getLocalizedDisplayname(
|
||||
MatrixLocals(L10n.of(context)!),
|
||||
);
|
||||
final filter = this.filter;
|
||||
if (filter != null && !displayname.toLowerCase().contains(filter)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
|
|
Loading…
Reference in a new issue