Files
Regroup/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart
2024-08-23 20:15:38 +05:30

900 lines
44 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:regroup/Common/CommonGlassmorphism.dart';
import 'package:regroup/Common/CommonWidget.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Utils/Common/CommonAppbar.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/dialogs.dart';
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});
@override
State<MyCommunity> createState() => _MyCommunityState();
}
class _MyCommunityState extends State<MyCommunity> {
List<int> isMuteList = [];
List<bool> isPinList = [];
bool? iscommunitypin = false;
var selectedContainerIndices = <int>{}.obs;
void toggleSelectedIndex(int index) {
if (selectedContainerIndices.contains(index)) {
selectedContainerIndices.remove(index);
} else {
selectedContainerIndices.add(index);
}
}
late Future myfuture;
@override
void initState() {
// TODO: implement initState
myfuture = MyCommunityAPI().getMyCommunity();
super.initState();
}
void refreshData() {
setState(() {
myfuture = MyCommunityAPI().getMyCommunity();
});
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
Get.toNamed(RouteName.mainscreen, arguments: 0);
return true;
},
child: Scaffold(
// key: _scaffoldKey1,
backgroundColor: const Color(0xFF222935),
extendBody: true,
resizeToAvoidBottomInset: false,
appBar: CommonAppbar(
customBack: true,
titleTxt: "My Communities",
customActionWidget: Row(
children: [
GestureDetector(
onTap: () async {
var result = await Get.toNamed(RouteName.newcommunity);
if (result != null && result) {
refreshData();
// CommunityDetail().getCommunityDetail(CommunityId);
print("Updating community details...");
// setState(() {});
}
},
child: Container(
height: 30.h,
width: 30.w,
decoration: const BoxDecoration(
color: Color(0xFFD90B2E),
boxShadow: [
BoxShadow(
color: Color(0x40000000),
offset: Offset(0, 6),
blurRadius: 8,
spreadRadius: 0,
),
],
shape: BoxShape.circle),
child: const Icon(
Icons.add,
color: Colors.white,
),
),
),
sizedBoxWidth(12.w),
Image.asset(
"assets/images/png/Frame 9.png",
height: 22.h,
width: 22.w,
)
],
),
),
body: FutureBuilder(
future: myfuture,
builder: (ctx, snapshot) {
if (snapshot.data == null) {
return const Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: CircularProgressIndicator(
color: Color(0xFFC18948),
),
)
],
);
}
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occured',
style: TextStyle(fontSize: 18.spMin),
),
);
}
}
// 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++) {
// Check if the current data item and its joinedAndRequestedCommunity property are not null
isMuteList.add(myCommunityobj!.data[i].isMute!);
if (myCommunityobj!.data[i].joinedAndRequestedCommunity != null) {
isPinList.add(myCommunityobj!
.data[i]
.joinedAndRequestedCommunity!
.isCommunityPinned!); // Handle null with a default value if needed
}
}
return Stack(children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/png/Ellipse 1496.png"),
fit: BoxFit.fill)),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(children: [
sizedBoxHeight(20.h),
Row(
children: [
Spacer(),
GestureDetector(
onTap: () async {
var result =
await Get.toNamed(RouteName.requestscreen);
if (result != null && result) {
refreshData();
// CommunityDetail().getCommunityDetail(CommunityId);
print("Updating community details...");
// setState(() {});
}
},
child:
text16w700_FCFCFC_line("Request and Invites"))
],
),
sizedBoxHeight(20.h),
myCommunityobj!.data!.isEmpty
? _buildNoDataBody(context)
: _buildBody(context),
]))
]);
},
),
),
);
}
Widget _buildNoDataBody(context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"No Data Found",
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontWeight: FontWeight.w600),
)
],
),
);
}
Widget _buildBody(context) {
return Expanded(
child: Column(children: [
sizedBoxHeight(20.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
physics: const ScrollPhysics(),
itemCount: myCommunityobj!.data.length,
itemBuilder: (context, index) {
var joinnedComData = myCommunityobj!.data[index];
return Padding(
padding: EdgeInsets.only(bottom: 25.h),
child: GestureDetector(
onTap: () async {
var result = await Get.toNamed(RouteName.communityDetails,
arguments: {
"CommunityID": joinnedComData.manageCommunityXid
});
if (result != null && result) {
refreshData();
print("Updating community details...");
}
},
child: commonGlassUI(
borderwidth: 0.9,
width: double.infinity,
height: 172.h,
borderRadius: BorderRadius.circular(10.r),
customWidget: Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.w, vertical: 16.h),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 65.h,
width: 65.h,
decoration: const BoxDecoration(
shape: BoxShape.circle,
// color: Colors.amber,
),
child:
// Center(
// child: Image.asset(imagepath, fit: BoxFit.cover)),
joinnedComData
.joinedAndRequestedCommunity !=
null &&
joinnedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto !=
null &&
joinnedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!
.isNotEmpty
? CircleAvatar(
backgroundImage: NetworkImage(
joinnedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!),
)
: const CircleAvatar(
backgroundImage: AssetImage(
'assets/images/png/img45.png'),
)),
sizedBoxWidth(13.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Container(
// // width: 250.w,
// // color: Colors.red,
// width: double.infinity,
// child:
SizedBox(
width: 200.w,
child: Text(
joinnedComData.joinedAndRequestedCommunity !=
null &&
joinnedComData
.joinedAndRequestedCommunity!
.communityName !=
null
? joinnedComData
.joinedAndRequestedCommunity!
.communityName!
: "",
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontFamily: "Nunito Sans",
),
maxLines:
2, // Set the maximum number of lines
overflow: TextOverflow
.ellipsis, // Truncate the text with an ellipsis
),
),
// ),
sizedBoxHeight(10.h),
joinnedComData.totalCommunityMember ==
null ||
joinnedComData.totalCommunityMember!
.toString()
.isEmpty
? const SizedBox()
: sizedBoxHeight(10.h),
Row(
children: [
Stack(
clipBehavior: Clip.none,
children: [
commonGlassUI(
borderwidth: 0.9,
width: 30.w,
height: 30.h,
borderRadius:
BorderRadius.circular(
100.r),
opacity1: 0.24,
opacity2: 0.24,
customWidget: Center(
child: Image.asset(
"assets/images/png/Black.png",
height: 12.h,
width: 16.w,
),
)),
// Positioned(
// top: 0,
// right: -4,
// child: Container(
// height: 12.h,
// width: 12.w,
// decoration:
// const BoxDecoration(
// shape:
// BoxShape.circle,
// color: Color(
// 0xFFD90B2E),
// ),
// child: Center(
// child:
// text6400white(
// "2")
// ),))
]),
sizedBoxWidth(15.w),
text14w400_FCFCFCblur(
"${joinnedComData.joinedAndRequestedCommunity != null && joinnedComData.joinedAndRequestedCommunity!.totalGroup != null ? joinnedComData.joinedAndRequestedCommunity!.totalGroup : ''} groups",
),
sizedBoxWidth(50.w),
GestureDetector(
onTap: () {
toggleSelectedIndex(index);
},
child: Container(
height: 21.h,
width: 57.w,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(50.r),
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(
255, 255, 255, 0.06),
Color.fromRGBO(
255, 255, 255, 0.08),
],
stops: [-0.0497, 1.0238],
// converting degrees to radians
),
border: Border.all(
color: const Color(0xFF434A53),
width: 1.0,
),
),
child: Center(
child: text10400white("Owner")),
),
),
],
),
],
),
const Spacer(),
PopupMenuButton(
surfaceTintColor: const Color(0xFF222935),
constraints:
BoxConstraints.tightFor(width: 200.w),
offset: const Offset(0, 30),
color: const Color(0xFF222935),
tooltip: "",
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[
PopupMenuItem(
onTap: () async {
Map<String, dynamic> updata = {
"manage_community_xid":
joinnedComData
.manageCommunityXid,
};
final data =
await CommunityDetail()
.postMuteNotification(
updata);
if (data.status ==
ResponseStatus.SUCCESS) {
if (isMuteList[index] == 1) {
isMuteList[index] = 0;
} else {
isMuteList[index] = 1;
}
await MyCommunityAPI()
.getMyCommunity();
// setState(() {});
return utils
.showToast(data.message);
} else {
Get.back();
print("Failed");
return utils
.showToast(data.message);
}
},
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 8.w),
child: Row(
children: [
isMuteList[index] == 1
? text14w400white(
"Unmute community")
: text14w400white(
"Mute community"),
const Spacer(),
isMuteList[index] == 1
? Image.asset(
"assets/images/png/Black1233.png",
height: 16.h,
width: 16.w,
)
: Image.asset(
"assets/images/png/Black1233.png",
height: 16.h,
width: 16.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () async {
// await pinunpinCommunity(
// myCommunityobj!
// .data[index]
// .joinedAndRequestedCommunity!
// .id
// .toString());
Map<String, dynamic> updata = {
"manage_communities_xid":
myCommunityobj!
.data[index]
.joinedAndRequestedCommunity!
.id
.toString(),
};
final data = await SidebarTags()
.postUserpin(updata);
if (data.status ==
ResponseStatus.SUCCESS) {
isPinList[index] =
!isPinList[index];
await MyCommunityAPI()
.getMyCommunity();
// setState(() {});
print("success");
// // Get.back();
// setState(() {});
// await MyCommunityAPI().getMyCommunity();
// iscommunitypin = !iscommunitypin!;
return utils
.showToast(data.message);
} else {
// Get.back();
return utils
.showToast(data.message);
}
},
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 12.w),
child: Row(
children: [
isPinList[index] == 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(),
isPinList[index] == 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 PopupMenuDivider(),
PopupMenuItem(
onTap: () async {
utils.loader();
Map<String, dynamic> updata = {};
final data =
await CommunityDetail()
.postLeaveCommunity(
updata,
joinnedComData
.manageCommunityXid,
);
if (data.status ==
ResponseStatus.SUCCESS) {
Get.back();
setState(() {
myCommunityobj!.data
.removeAt(index);
});
return utils
.showToast(data.message);
} else {
Get.back();
return utils
.showToast(data.message);
}
},
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 8.w),
child: Row(
children: [
// text14w400_FCFCFC("Leave group"),
text14w400_D90B2E(
"Leave Community"),
const Spacer(),
Image.asset(
"assets/images/png/LightGray22.png",
height: 18.h,
width: 18.w,
)
],
),
),
),
],
child: Image.asset(
"assets/images/png/Group 1000004071.png",
height: 18.h,
width: 20.w,
)),
],
),
sizedBoxHeight(16.h),
commonDivider(),
sizedBoxHeight(10.h),
Row(
children: [
stackContainersGroups(
number:
" +${joinnedComData.totalCommunityMember! - 3}",
// containerImages: joinnedComData
// .fourMemberImages!
// .map((photo) => photo
// .iamPrincipal!.profilePhoto!)
// .toList(),
containerImages: joinnedComData
.fourMemberImages
?.map((photo) =>
photo.iamPrincipal?.profilePhoto)
.where((profilePhoto) =>
profilePhoto != null)
.map((profilePhoto) =>
profilePhoto!) // Cast from String? to String
.toList() ??
[],
),
sizedBoxWidth(75.w),
joinnedComData.totalCommunityMember == null ||
joinnedComData
.totalCommunityMember.isBlank!
? const SizedBox()
: text16w400_FCFCFC_blur(
'${joinnedComData.totalCommunityMember} members',
),
Spacer(),
Image.asset(
"assets/images/png/arrow.png",
height: 21.h,
width: 18.w,
),
],
)
],
),
)),
),
);
},
),
)
]),
);
}
Widget communityCard({
required String imagepath,
required String title,
required void Function()? ontap,
required String members,
required int index,
}) {
return Padding(
padding: EdgeInsets.only(bottom: 25.h),
child: GestureDetector(
onTap: ontap,
child: commonGlassUI(
width: double.infinity,
height: 162.h,
borderwidth: 0.9,
borderRadius: BorderRadius.circular(10.r),
customWidget: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 65.h,
width: 65.h,
decoration: const BoxDecoration(
shape: BoxShape.circle,
// color: Colors.amber,
),
child:
// Center(
// child: Image.asset(imagepath, fit: BoxFit.cover)),
CircleAvatar(
backgroundImage: AssetImage(
imagepath,
),
),
),
sizedBoxWidth(13.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text18w700_FCFCFC(title),
sizedBoxHeight(10.h),
Row(
children: [
Stack(clipBehavior: Clip.none, children: [
commonGlassUI(
borderwidth: 0.9,
width: 30.w,
height: 30.h,
borderRadius: BorderRadius.circular(100.r),
opacity1: 0.24,
opacity2: 0.24,
customWidget: Center(
child: Image.asset(
"assets/images/png/Black.png",
height: 12.h,
width: 16.w,
),
)),
Positioned(
top: 0,
right: -4,
child: Container(
height: 12.h,
width: 12.w,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFFD90B2E),
),
child: Center(child: text6400white("2")),
))
]),
sizedBoxWidth(15.w),
text14w400_FCFCFCblur("10 groups")
],
),
],
),
const Spacer(),
PopupMenuButton(
surfaceTintColor: const Color(0xFF222935),
constraints: BoxConstraints.tightFor(width: 200.w),
offset: const Offset(0, 30),
color: const Color(0xFF222935),
tooltip: "",
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC("Mute community"),
const Spacer(),
Image.asset(
"assets/images/png/Black (1).png",
height: 18.h,
width: 18.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC("Hide post"),
const Spacer(),
Image.asset(
"assets/images/png/mingcute_eye-close-line.png",
height: 20.h,
width: 20.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC("Pin"),
const Spacer(),
Image.asset(
"assets/images/png/f7_pin-fill (2).png",
height: 25.h,
width: 25.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC("Leave community"),
const Spacer(),
Image.asset(
"assets/images/png/logout 1 (traced).png",
height: 18.h,
width: 18.w,
)
],
),
),
),
],
child: Image.asset(
"assets/images/png/Group 1000004071.png",
height: 18.h,
width: 20.w,
)),
],
),
sizedBoxHeight(16.h),
commonDivider(),
sizedBoxHeight(10.h),
Expanded(
child: Row(
children: [
stackContainers(
number: "+2",
containerImages: [
"assets/images/png/cimg3.png",
"assets/images/png/cimg2.png",
"assets/images/png/cimg3.png",
"assets/images/png/cimg2.png",
],
),
sizedBoxWidth(95.w),
text12w400_FCFCFC_blur(members),
const Spacer(),
Obx(() {
return GestureDetector(
onTap: () {
toggleSelectedIndex(index);
},
child: Container(
width: selectedContainerIndices.contains(index)
? 118.w
: 100.w,
height: 30.h,
decoration: BoxDecoration(
color:
selectedContainerIndices.contains(index)
? null
: const Color(0xFFD90B2E),
borderRadius: BorderRadius.all(
Radius.circular(30.r),
),
border: Border.all(
color: const Color(0xFFD90B2E),
width: 1.w)),
child: Center(
child:
selectedContainerIndices.contains(index)
? text14400white("Requested")
: text14400white("Joined")),
),
);
})
],
),
)
],
),
)),
),
);
}
}