pin unpin problem solved

This commit is contained in:
Dakshesh42
2024-08-22 20:18:41 +05:30
parent 1dab461497
commit 111bce4390
2 changed files with 136 additions and 56 deletions

View File

@@ -33,7 +33,7 @@ class CommunityDetails extends StatefulWidget {
class _CommunityDetailsState extends State<CommunityDetails> {
var additionalContent = false.obs;
bool? iscommunitypin = false;
late Future myfuture;
@@ -43,6 +43,7 @@ class _CommunityDetailsState extends State<CommunityDetails> {
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<CommunityDetails> {
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<CommunityDetails> {
),
),
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<CommunityDetails> {
);
}
}
iscommunitypin = comdetailobj?.data?.isCommunityPinned;
ismute = comdetailobj?.data?.userLinkInCommunity?.isMute;
return Stack(children: [
Container(

View File

@@ -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<MyCommunity> {
int? ismute;
bool? iscommunitypin = false;
List JoinedcommunityData = [
{
"imagePath": "assets/images/png/img2.png",
@@ -74,6 +76,26 @@ class _MyCommunityState extends State<MyCommunity> {
super.initState();
}
pinunpinCommunity(String communitypinid) async {
// utils.loader();
Map<String, dynamic> 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<MyCommunity> {
);
}
}
// 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<MyCommunity> {
),
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,
)
],
),
),