Files
Regroup/lib/sidemenu/Community/MyCommunity/View/RequestsScreen.dart
2024-08-13 19:55:56 +05:30

1061 lines
64 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/CommonTabBar.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/sidemenu/view_model/getMyCommunity.dart';
class RequestsScreen extends StatefulWidget {
const RequestsScreen({super.key});
@override
State<RequestsScreen> createState() => _RequestsScreenState();
}
class _RequestsScreenState extends State<RequestsScreen> {
late Future myfuture;
@override
void initState() {
// TODO: implement initState
// myfuture = MyCommunityAPI().getMyCommunity();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
// key: _scaffoldKey1,
backgroundColor: const Color(0xFF222935),
extendBody: true,
resizeToAvoidBottomInset: false,
appBar: CommonAppbar(
titleTxt: "My Communities",
customActionWidget: Row(
children: [
sizedBoxWidth(12.w),
Image.asset(
"assets/images/png/Frame 9.png",
height: 22.h,
width: 22.w,
)
],
),
),
body: Stack(children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/png/Ellipse 1496.png"),
fit: BoxFit.fill)),
),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
sizedBoxHeight(20.h),
const Expanded(
child: DefaultTabController(
length: 2,
child: Column(
children: [
CommonTabBar(tabs: [
Tab(
text: 'Requested',
),
Tab(
text: 'Invited',
),
]),
Expanded(
child: TabBarView(
children: [
RequestedTab(),
InvitedTab(),
],
),
),
],
)),
)
])
]));
}
}
class RequestedTab extends StatefulWidget {
const RequestedTab({super.key});
@override
State<RequestedTab> createState() => _RequestedTabState();
}
class _RequestedTabState extends State<RequestedTab> {
late Future myfuture;
@override
void initState() {
// TODO: implement initState
myfuture = MyCommunityAPI().getRequestedCommunity();
super.initState();
}
@override
Widget build(BuildContext context) {
return 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 requestedComobj!.data.isEmpty
? _buildNoDataBody(context)
: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Column(
children: [
sizedBoxHeight(20.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
physics: const ScrollPhysics(),
itemCount: requestedComobj!.data.length,
itemBuilder: (context, index) {
var requestedComData = requestedComobj!.data[index];
return Padding(
padding: EdgeInsets.only(bottom: 25.h),
child: GestureDetector(
onTap: () {},
child: commonGlassUI(
borderwidth: 0.9,
width: double.infinity,
height: 180.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)),
requestedComData.joinedAndRequestedCommunity!
.communityProfilePhoto ==
null ||
requestedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!
.isEmpty
? const CircleAvatar(
backgroundImage:
AssetImage(
'assets/images/png/img45.png',
),
)
: CircleAvatar(
backgroundImage: NetworkImage(
requestedComData
.joinedAndRequestedCommunity!
.communityProfilePhoto!),
)),
sizedBoxWidth(13.w),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
// Container(
// // width: 250.w,
// // color: Colors.red,
// width: double.infinity,
// child:
requestedComData.joinedAndRequestedCommunity!
.communityName ==
null ||
requestedComData
.joinedAndRequestedCommunity!
.communityName!
.isEmpty
? text18w700_FCFCFC(
'Regroup')
: SizedBox(
width: 200.w,
child: text18w700_FCFCFC(
requestedComData
.joinedAndRequestedCommunity!
.communityName!),
),
// ),
sizedBoxHeight(10.h),
requestedComData.totalCommunityMember ==
null ||
requestedComData
.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(
"${requestedComData.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),
Expanded(
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
stackContainersGroups(
number:
" +${requestedComData.totalCommunityMember! - 3}",
containerImages:
requestedComData
.fourMemberImages!
.map((photo) => photo
.iamPrincipal!
.profilePhoto!)
.toList(),
),
sizedBoxWidth(75.w),
requestedComData.totalCommunityMember ==
null ||
requestedComData
.totalCommunityMember!
.isBlank!
? const SizedBox()
: text16w400_FCFCFC_blur(
'${requestedComData.totalCommunityMember} members',
),
Spacer(),
GestureDetector(
onTap: () async {
Map<String, dynamic>
updata = {
"manage_community_xid":
requestedComData
.manageCommunityXid
};
final data =
await MyCommunityAPI()
.postcancelRequest(
updata);
if (data.status ==
ResponseStatus
.SUCCESS) {
print("success");
setState(() {
requestedComobj!.data
.removeAt(index);
});
return utils.showToast(
data.message);
} else {
Get.back();
print("Failed");
return utils.showToast(
data.message);
}
},
child: Container(
height: 30.h,
width: 120.w,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(30.r),
color:
Color(0xFFD90B2E)),
child: Center(
child: text12w400_FCFCFC(
"Cancel request")),
),
)
],
),
)
],
),
)),
),
);
},
),
),
],
),
);
});
}
}
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),
)
],
),
);
}
class InvitedTab extends StatefulWidget {
const InvitedTab({super.key});
@override
State<InvitedTab> createState() => _InvitedTabState();
}
class _InvitedTabState extends State<InvitedTab> {
late Future myfuture;
@override
void initState() {
// TODO: implement initState
myfuture = MyCommunityAPI().getInviteCommunity();
super.initState();
}
@override
Widget build(BuildContext context) {
return 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 inviteComobj!.data.isEmpty
? _buildNoDataBody(context)
: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Column(
children: [
sizedBoxHeight(20.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
physics: const ScrollPhysics(),
itemCount: inviteComobj!.data.length,
itemBuilder: (context, index) {
var invitedComData = inviteComobj!.data[index];
return Padding(
padding: EdgeInsets.only(bottom: 25.h),
child: GestureDetector(
onTap: () {},
child: commonGlassUI(
borderwidth: 0.9,
width: double.infinity,
height: 180.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)),
invitedComData.senderDetail!
.profilePhoto ==
null ||
invitedComData
.senderDetail!
.profilePhoto!
.isEmpty
? const CircleAvatar(
backgroundImage:
AssetImage(
'assets/images/png/img45.png',
),
)
: CircleAvatar(
backgroundImage: NetworkImage(
invitedComData
.senderDetail!
.profilePhoto!),
)),
sizedBoxWidth(13.w),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Container(
// width: 250.w,
// color: Colors.red,
// width: double.infinity,
child: invitedComData
.senderDetail!
.fullName ==
null ||
invitedComData
.senderDetail!
.fullName!
.isEmpty
? text18w700_FCFCFC(
'Regroup')
: SizedBox(
width: 200.w,
child: text18w700_FCFCFC(
invitedComData
.senderDetail!
.fullName!),
),
),
sizedBoxHeight(10.h),
// invitedComData.totalCommunityMember ==
// null ||
// joinnedComData
// .totalCommunityMember!
// .toString()
// .isEmpty
// ? const SizedBox()
// : sizedBoxHeight(10.h),
Row(
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,
),
)),
sizedBoxWidth(15.w),
// text14w400_FCFCFCblur(
// "${invitedComData.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),
Expanded(
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
// stackContainersGroups(
// number:
// " +${invitedComData.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',
// ),
Spacer(),
GestureDetector(
onTap: () async {
Map<String, dynamic>
updata = {
"community_xid":
invitedComData
.communityXid
};
final data =
await MyCommunityAPI()
.postRejectInvite(
updata);
if (data.status ==
ResponseStatus
.SUCCESS) {
print("success");
setState(() {
inviteComobj!.data
.removeAt(index);
});
return utils.showToast(
data.message);
} else {
Get.back();
print("Failed");
return utils.showToast(
data.message);
}
},
child: Container(
height: 30.h,
width: 70.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(
"Reject")),
),
),
sizedBoxWidth(6.w),
GestureDetector(
onTap: () async {
Map<String, dynamic>
updata = {
"community_xid":
invitedComData
.communityXid
};
final data =
await MyCommunityAPI()
.postAcceptInvite(
updata);
if (data.status ==
ResponseStatus
.SUCCESS) {
print("success");
setState(() {
inviteComobj!.data
.removeAt(index);
});
return utils.showToast(
data.message);
} else {
Get.back();
print("Failed");
return utils.showToast(
data.message);
}
},
child: Container(
height: 30.h,
width: 70.w,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(30.r),
color:
Color(0xFFD90B2E)),
child: Center(
child:
text12w400_FCFCFC(
"Accept")),
),
)
],
),
)
],
),
)),
),
);
},
),
),
],
),
);
});
}
}
// 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),
// )
// ],
// ),
// );
// }