Files
Regroup/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart
2024-08-16 19:33:44 +05:30

750 lines
36 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/Utils/Common/CommonAppbar.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:regroup/resources/routes/route_name.dart';
import 'package:regroup/sidemenu/view_model/getMyCommunity.dart';
class MyCommunity extends StatefulWidget {
const MyCommunity({super.key});
@override
State<MyCommunity> createState() => _MyCommunityState();
}
class _MyCommunityState extends State<MyCommunity> {
List JoinedcommunityData = [
{
"imagePath": "assets/images/png/img2.png",
"text": "Active alliance network",
"members": "7 members",
"index": 1,
},
{
"imagePath": "assets/images/png/img34.png",
"text": "FitFam federation",
"members": "7 members",
"index": 2,
},
];
List RequestcommunityData = [
{
"imagePath": "assets/images/png/img45.png",
"text": "The athletic town",
"members": "7 members",
"index": 3,
},
{
"imagePath": "assets/images/png/img2.png",
"text": "Football fever",
"members": "7 members",
"index": 4,
},
];
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();
}
@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(
titleTxt: "My Communities",
customActionWidget: Row(
children: [
GestureDetector(
onTap: () {
Get.toNamed(RouteName.newcommunity);
},
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),
),
);
}
}
return 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 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: () {
Get.toNamed(RouteName.requestscreen);
},
child: text16w700_FCFCFC_line("Requests"))
],
),
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: () {
Get.toNamed(RouteName.communityDetails, arguments: {
"CommunityID": joinnedComData.manageCommunityXid
});
},
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!
.communityProfilePhoto ==
null ||
joinnedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!
.isEmpty
? const CircleAvatar(
backgroundImage:
AssetImage(
'assets/images/png/img45.png',
),
)
: CircleAvatar(
backgroundImage: NetworkImage(
joinnedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!),
)),
sizedBoxWidth(13.w),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
// Container(
// // width: 250.w,
// // color: Colors.red,
// width: double.infinity,
// child:
joinnedComData.joinedAndRequestedCommunity!
.communityName ==
null ||
joinnedComData
.joinedAndRequestedCommunity!
.communityName!
.isEmpty
? text18w700_FCFCFC('Regroup')
: SizedBox(
width: 200.w,
child: text18w700_FCFCFC(
joinnedComData
.joinedAndRequestedCommunity!
.communityName!),
),
// ),
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!.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: () {},
child: Padding(
padding:
EdgeInsets.symmetric(
horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC(
"Mute group"),
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(
"Pin group"),
const Spacer(),
Image.asset(
"assets/images/png/f7_pin-fill (2).png",
height: 27.h,
width: 27.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(
horizontal: 8.w),
child: Row(
children: [
text14w400_FCFCFC(
"Make primary"),
const Spacer(),
Image.asset(
"assets/images/png/leave group.png",
height: 20.h,
width: 20.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding:
EdgeInsets.symmetric(
horizontal: 8.w),
child: Row(
children: [
// text14w400_FCFCFC("Leave group"),
text14w400_D90B2E(
"Leave group"),
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(),
),
sizedBoxWidth(75.w),
joinnedComData.totalCommunityMember ==
null ||
joinnedComData
.totalCommunityMember.isBlank!
? const SizedBox()
: text16w400_FCFCFC_blur(
'${joinnedComData.totalCommunityMember} members',
),
],
)
],
),
)),
),
);
},
),
),
],
))
]);
}
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")),
),
);
})
],
),
)
],
),
)),
),
);
}
}