From 27e6a9f165bc84317a1288c57d52265335950458 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Wed, 27 Sep 2023 12:08:45 +0700 Subject: [PATCH] Can longPress on item in chat list and fix can't remove item already exists --- lib/pages/chat_list/chat_list.dart | 4 ++-- lib/pages/chat_list/chat_list_body.dart | 6 ++++++ lib/pages/chat_list/chat_list_item.dart | 3 +++ lib/widgets/twake_components/twake_header.dart | 6 +++--- lib/widgets/twake_components/twake_header_style.dart | 2 ++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index b76f94763b..a39adb1004 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -268,8 +268,8 @@ class ChatListController extends State tempConversationSelectionPresentation = conversationSelectionNotifier.value.toSet(); - if (conversation != null) { - conversationSelectionNotifier.value.toSet().remove(conversation); + if (conversation != null && conversation.isSelected) { + tempConversationSelectionPresentation.remove(conversation); } else { tempConversationSelectionPresentation.add( ConversationSelectionPresentation( diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index 491ef5458e..c19a5dec38 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -185,6 +185,12 @@ class ChatListViewBody extends StatelessWidget { context, rooms[index], ), + onLongPress: () { + controller.toggleSelectMode(); + controller.toggleSelection( + rooms[index].id, + ); + }, checkBoxWidget: ValueListenableBuilder( valueListenable: controller.conversationSelectionNotifier, diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index f2e013b195..b4143af0f6 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -23,6 +23,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { final void Function()? onTap; final void Function()? onTapAvatar; final void Function()? onSecondaryTap; + final void Function()? onLongPress; const ChatListItem( this.room, { @@ -33,6 +34,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { this.onTap, this.onTapAvatar, this.onSecondaryTap, + this.onLongPress, Key? key, }) : super(key: key); @@ -100,6 +102,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { child: InkWell( onTap: () => clickAction(context), onSecondaryTap: onSecondaryTap, + onLongPress: onLongPress, child: Container( padding: ChatListItemStyle.paddingBody, child: Row( diff --git a/lib/widgets/twake_components/twake_header.dart b/lib/widgets/twake_components/twake_header.dart index 6968b5d3cb..29d9ead293 100644 --- a/lib/widgets/twake_components/twake_header.dart +++ b/lib/widgets/twake_components/twake_header.dart @@ -38,7 +38,7 @@ class TwakeHeader extends StatelessWidget child: Row( children: [ Expanded( - flex: 3, + flex: TwakeHeaderStyle.flexActions, child: Row( children: [ InkWell( @@ -79,7 +79,7 @@ class TwakeHeader extends StatelessWidget ), ), Expanded( - flex: 6, + flex: TwakeHeaderStyle.flexTitle, child: Align( alignment: Alignment.center, child: Text( @@ -92,7 +92,7 @@ class TwakeHeader extends StatelessWidget ), if (!TwakeHeaderStyle.isDesktop(context)) Expanded( - flex: 3, + flex: TwakeHeaderStyle.flexActions, child: Align( alignment: Alignment.centerRight, child: InkWell( diff --git a/lib/widgets/twake_components/twake_header_style.dart b/lib/widgets/twake_components/twake_header_style.dart index eba2530b39..aae4b6a5f7 100644 --- a/lib/widgets/twake_components/twake_header_style.dart +++ b/lib/widgets/twake_components/twake_header_style.dart @@ -10,6 +10,8 @@ class TwakeHeaderStyle { static const double closeIconSize = 24.0; static const double widthSizedBox = 16.0; static const double textBorderRadius = 24.0; + static const int flexTitle = 6; + static const int flexActions = 3; static bool isDesktop(BuildContext context) => responsive.isDesktop(context);