From 111bce43902a18ddc2a03ae4b0fc95146e70c117 Mon Sep 17 00:00:00 2001 From: Dakshesh42 Date: Thu, 22 Aug 2024 20:18:41 +0530 Subject: [PATCH] pin unpin problem solved --- .../MyCommunity/View/CommunityDetails.dart | 94 +++++++++--------- .../MyCommunity/View/MyCommunity.dart | 98 +++++++++++++++++-- 2 files changed, 136 insertions(+), 56 deletions(-) diff --git a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart index cd96f7a..91f7456 100644 --- a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart +++ b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart @@ -33,7 +33,7 @@ class CommunityDetails extends StatefulWidget { class _CommunityDetailsState extends State { var additionalContent = false.obs; - + bool? iscommunitypin = false; late Future myfuture; @@ -43,6 +43,7 @@ class _CommunityDetailsState extends State { CommunityId = Get.arguments["CommunityID"]; myfuture = CommunityDetail().getCommunityDetail(CommunityId); ismute = comdetailobj?.data?.userLinkInCommunity?.isMute; + iscommunitypin = comdetailobj?.data?.isCommunityPinned; super.initState(); } @@ -61,10 +62,10 @@ class _CommunityDetailsState extends State { if (data.status == ResponseStatus.SUCCESS) { print("success"); // Get.back(); - setState(() { - iscommunitypin = !iscommunitypin!; - CommunityDetail().getCommunityDetail(CommunityId); - }); + setState(() {}); + await CommunityDetail().getCommunityDetail(CommunityId); + iscommunitypin = !iscommunitypin!; + return utils.showToast(data.message); } else { // Get.back(); @@ -212,50 +213,50 @@ class _CommunityDetailsState extends State { ), ), const PopupMenuDivider(), - PopupMenuItem( - onTap: () async { - await pinunpinCommunity( - comdetailobj!.data!.id.toString()); - }, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 12.w), - child: Row( - children: [ - iscommunitypin == true - ? Text( - 'Unpin', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", + PopupMenuItem( + onTap: () async { + await pinunpinCommunity( + comdetailobj!.data!.id.toString()); + }, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 12.w), + child: Row( + children: [ + iscommunitypin == true + ? Text( + 'Unpin', + style: TextStyle( + fontSize: 16.sp, + color: Colors.white, + fontWeight: FontWeight.w800, + fontFamily: "Nunito Sans", + ), + ) + : Text( + 'Pin', + style: TextStyle( + fontSize: 16.sp, + color: Colors.white, + fontWeight: FontWeight.w800, + fontFamily: "Nunito Sans", + ), ), - ) - : Text( - 'Pin', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", - ), - ), - const Spacer(), - iscommunitypin == true - ? Image.asset( - "assets/images/png/PinnedIcon.png", - height: 25.h, - width: 25.w, - ) - : Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 25.h, - width: 25.w, - ) - ], + const Spacer(), + iscommunitypin == true + ? Image.asset( + "assets/images/png/PinnedIcon.png", + height: 25.h, + width: 25.w, + ) + : Image.asset( + "assets/images/png/f7_pin-fill (2).png", + height: 25.h, + width: 25.w, + ) + ], + ), ), ), - ), if (comdetailobj!.data!.accessType!.name == "Member") const PopupMenuDivider(), if (comdetailobj!.data!.accessType!.name == "Member") @@ -333,6 +334,7 @@ class _CommunityDetailsState extends State { ); } } + iscommunitypin = comdetailobj?.data?.isCommunityPinned; ismute = comdetailobj?.data?.userLinkInCommunity?.isMute; return Stack(children: [ Container( diff --git a/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart b/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart index a572c26..7ce9005 100644 --- a/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart +++ b/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart @@ -14,6 +14,7 @@ import 'package:regroup/Utils/texts.dart'; import 'package:regroup/resources/routes/route_name.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/view_model/ComDetails.dart'; import 'package:regroup/sidemenu/view_model/getMyCommunity.dart'; +import 'package:regroup/sidemenu/view_model/postmethod.dart'; class MyCommunity extends StatefulWidget { const MyCommunity({super.key}); @@ -24,6 +25,7 @@ class MyCommunity extends StatefulWidget { class _MyCommunityState extends State { int? ismute; + bool? iscommunitypin = false; List JoinedcommunityData = [ { "imagePath": "assets/images/png/img2.png", @@ -74,6 +76,26 @@ class _MyCommunityState extends State { super.initState(); } + pinunpinCommunity(String communitypinid) async { + // utils.loader(); + Map updata = { + "manage_communities_xid": communitypinid, + }; + final data = await SidebarTags().postUserpin(updata); + if (data.status == ResponseStatus.SUCCESS) { + print("success"); + // Get.back(); + setState(() {}); + await MyCommunityAPI().getMyCommunity(); + iscommunitypin = !iscommunitypin!; + + return utils.showToast(data.message); + } else { + // Get.back(); + return utils.showToast(data.message); + } + } + @override Widget build(BuildContext context) { return WillPopScope( @@ -149,8 +171,22 @@ class _MyCommunityState extends State { ); } } + // for (int i = 0; i < myCommunityobj!.data.length; i++) { + // ismute = myCommunityobj!.data[i].isMute; + // iscommunitypin = myCommunityobj! + // .data[i].joinedAndRequestedCommunity!.isCommunityPinned; + // } for (int i = 0; i < myCommunityobj!.data.length; i++) { - ismute = myCommunityobj!.data[i].isMute; + // Check if the current data item and its joinedAndRequestedCommunity property are not null + + ismute = myCommunityobj! + .data[i].isMute; // Handle null with a default value if needed + + if (myCommunityobj!.data[i].joinedAndRequestedCommunity != null) { + iscommunitypin = myCommunityobj!.data[i] + .joinedAndRequestedCommunity!.isCommunityPinned ?? + false; // Handle null with a default value if needed + } } return myCommunityobj!.data!.isEmpty @@ -472,21 +508,63 @@ class _MyCommunityState extends State { ), const PopupMenuDivider(), PopupMenuItem( - onTap: () {}, + onTap: () async { + await pinunpinCommunity( + myCommunityobj! + .data[index] + .joinedAndRequestedCommunity! + .id + .toString()); + }, child: Padding( padding: EdgeInsets.symmetric( - horizontal: 8.w), + horizontal: 12.w), child: Row( children: [ - text14w400_FCFCFC( - "Pin group"), + iscommunitypin == true + ? Text( + 'Unpin ', + style: + TextStyle( + fontSize: + 16.sp, + color: Colors + .white, + fontWeight: + FontWeight + .w800, + fontFamily: + "Nunito Sans", + ), + ) + : Text( + 'Pin ', + style: + TextStyle( + fontSize: + 16.sp, + color: Colors + .white, + fontWeight: + FontWeight + .w800, + fontFamily: + "Nunito Sans", + ), + ), const Spacer(), - Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 27.h, - width: 27.w, - ) + iscommunitypin == true + ? Image.asset( + "assets/images/png/PinnedIcon.png", + height: 25.h, + width: 25.w, + ) + : Image.asset( + "assets/images/png/f7_pin-fill (2).png", + height: 25.h, + width: 25.w, + ) ], ), ),