Files
Regroup/lib/Feed Module/Main_Screens/ProfileTab/Settings/View/BlockedUsers.dart

319 lines
11 KiB
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/Feed%20Module/Main_Screens/ProfileTab/Settings/ViewModel/BlockedUserApi.dart';
import 'package:regroup/Utils/Common/CommonAppbar.dart';
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BlockedUsers extends StatefulWidget {
const BlockedUsers({super.key});
@override
State<BlockedUsers> createState() => _BlockedUsersState();
}
class _BlockedUsersState extends State<BlockedUsers> {
List blockedUserData = [
{
"imagePath": "assets/images/png/cimg1.png",
"title": "Ryan Dorwart",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/cimg2.png",
"title": "Ahmad Rhiel Madsen",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/cimg3.png",
"title": "Kaylynn Vaccaro",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/cimg4.png",
"title": "Kianna Donin",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/Ellipse 43.png",
"title": "Maria Herwitz",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/Ellipse 52.png",
"title": "Ahmad Rhiel Madsen",
"subtitle": "Lorem ipsum dummy text",
},
{
"imagePath": "assets/images/png/img2.png",
"title": "Kaylynn Vaccaro",
"subtitle": "Lorem ipsum dummy text",
},
];
late Future myfuture;
double? blockedXid;
unblockDone(int index) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt('blockedprincipalxid',
fetchblockuser!.data![index].blockedIamPrincipalXid!);
blockedXid = prefs.getInt('blockedprincipalxid')!.toDouble();
Map<String, String> updata = {
"blocked_iam_principal_xid": blockedXid.toString(),
};
final resp = await BlockUserAPI().postBlockApi(updata);
if (resp.status == ResponseStatus.SUCCESS) {
Get.snackbar(
"Success!",
'Unblock user successfully',
duration: Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.green,
margin: EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
// utils.showToast('Unblock user successfully');
setState(() {
fetchblockuser!.data!.removeAt(index);
});
print('success');
} else {
// btnController.error();
// btnController.reset();
Get.snackbar(
"Error!",
resp.data['message'],
duration: Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.red,
margin: EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
}
}
@override
void initState() {
myfuture = BlockUserAPI().fetchBlockUser();
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
// key: _scaffoldKey1,
resizeToAvoidBottomInset: false,
backgroundColor: Color(0xFF222935),
extendBody: true,
appBar: CommonAppbar(
titleTxt: "Blocked users",
),
body: FutureBuilder(
future: myfuture,
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(
color: Colors.blue,
),
);
}
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occurred',
style: TextStyle(fontSize: 18.spMin),
),
);
}
if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) {
print("Data fetched-->");
return 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(25.h),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: CustomTextFormField(
leadingIcon: SizedBox(
height: 23,
width: 23,
child: Center(
child: Image.asset(
"assets/images/png/ion_search-outline.png",
height: 23,
width: 23,
),
),
),
hintText: "Search people",
),
),
sizedBoxHeight(25.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: fetchblockuser!.data!.length,
itemBuilder: (context, index) {
return Column(
children: [
blockedUser(
imagePath: fetchblockuser!.data![index]
.blockedProfile!.profilePhoto ??
'',
title: fetchblockuser!.data![index]
.blockedProfile!.fullName ??
'',
subtitle: fetchblockuser!.data![index]
.blockedProfile!.userName ??
'',
index: index),
// blockedUser(
// imagePath: blockedUserData[index]
// ["imagePath"],
// title: blockedUserData[index]["title"],
// subtitle: blockedUserData[index]
// ["subtitle"]),
if (index != fetchblockuser!.data!.length - 1)
commonDivider(),
],
);
},
),
),
sizedBoxHeight(20.h)
])
]);
}
return Container();
}));
}
dialogwidget({required int index}) {
Get.dialog(Dialog(
backgroundColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
child: commonGlassContainer(
width: double.infinity,
height: 200.h,
borderradius: 14,
opacity1: 0.09,
opacity2: 0.13,
customWidget: Padding(
padding: EdgeInsets.symmetric(horizontal: 30.w, vertical: 30.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text18w400_FCFCFC(
"Are you sure you want to unblock the user?",
textAlign: TextAlign.center),
sizedBoxHeight(30.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
Get.back();
},
child: commonGlassContainer(
width: 110.w,
height: 40.h,
borderradius: 30.r,
opacity1: 0.05,
opacity2: 0.07,
customWidget: Center(child: text14400white("No")),
border: 1),
),
InkWell(
onTap: () {
// Get.back();
unblockDone(index);
// await BlockUserAPI().fetchBlockUser();
Get.back();
// setState(() {});
},
child: Container(
height: 40.h,
width: 110.w,
decoration: BoxDecoration(
color: Color(0xFFD90B2E),
borderRadius: BorderRadius.circular(30.r),
),
child: Center(child: text14400white("Yes")),
),
)
],
),
],
),
),
border: 0.8)));
}
Widget blockedUser({
required String imagePath,
required String title,
required String subtitle,
required int index,
}) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 16.w),
child: Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage(imagePath),
// AssetImage(imagePath),
radius: 25.r,
),
sizedBoxWidth(10.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16w400_FCFCFC(title),
sizedBoxHeight(4.h),
text12w400_FCFCFC_blur(subtitle),
],
),
Spacer(),
GestureDetector(
onTap: () {
dialogwidget(index: index);
},
child: Container(
height: 30.h,
width: 105.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.r),
color: Color(0xFFD90B2E)),
child: Center(child: text14w400_FCFCFC("Unblock")),
),
)
],
),
);
}
}