Files
Regroup/lib/onboarding/Signup/View/Individual/step4Selectyourcommunity.dart
2024-07-29 15:20:19 +05:30

410 lines
16 KiB
Dart

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:glassmorphism/glassmorphism.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Utils/Common/CustomNextButton.dart';
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
import 'package:regroup/Utils/Common/blureffect.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/dialogs.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:regroup/onboarding/Signup/Model/Onboarding/Individual/CommunitiesModel.dart';
import 'package:regroup/onboarding/Signup/view_model/getmethod.dart';
import 'package:regroup/onboarding/Signup/view_model/postmethod.dart';
import 'package:regroup/resources/routes/route_name.dart';
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
class SelectIndividualCommunity extends StatefulWidget {
const SelectIndividualCommunity({super.key});
@override
State<SelectIndividualCommunity> createState() =>
_SelectIndividualCommunityState();
}
class _SelectIndividualCommunityState extends State<SelectIndividualCommunity> {
StreamController<GetcommunitiesModel> searchcontroller = StreamController();
@override
void initState() {
var updata = "";
Getonboard().getCommunitysearch(updata, streamController: searchcontroller);
super.initState();
}
@override
void dispose() {
searchcontroller.close();
super.dispose();
}
final List<int> _selectedIndices = [];
void _onContainerTap(int id) {
setState(() {
if (_selectedIndices.contains(id)) {
_selectedIndices.remove(id);
} else {
_selectedIndices.add(id);
}
});
}
uploadata() async {
utils.loader();
String selectedIndicesString = '[${_selectedIndices.join(',')}]';
print('Selected Indices: $selectedIndicesString');
Map<String, dynamic> updata = {
"manage_community_xid": selectedIndicesString,
};
print('Payload: $updata');
final data = await Onboard().postCommunities(updata);
if (data.status == ResponseStatus.SUCCESS) {
// Get.back();
print("groups selected");
Get.toNamed(RouteName.communitycommitscreen);
return utils.showToast(data.message);
} else {
Get.back();
print("Not done");
return utils.showToast(data.message);
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
backgroundColor: const Color.fromARGB(255, 18, 32, 47),
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/png/Ellipse 1496.png"),
fit: BoxFit.fill)),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 40.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.topRight,
child: GestureDetector(
onTap: () {
Get.toNamed(RouteName.communitycommitscreen);
},
child: Text(
'Skip',
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
decoration: TextDecoration.underline,
decorationColor: Colors.white),
),
),
),
sizedBoxHeight(30.h),
Align(
alignment: Alignment.center,
child: text16400white('Step 3 of 3')),
sizedBoxHeight(20.h),
Container(
width: double.infinity,
height: 25.h,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: const BorderSide(width: 1, color: Color(0xFF434A53)),
borderRadius: BorderRadius.circular(30),
),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 2.h),
child: Row(
children: [
Expanded(
child: Container(
// width: 216.w,
height: 15.h,
decoration: ShapeDecoration(
gradient: const LinearGradient(
begin: Alignment(0.98, -0.21),
end: Alignment(-0.98, 0.21),
colors: [
Color(0xA5D90B2E),
Color(0x42D90B2E)
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 15,
height: 15,
decoration: ShapeDecoration(
gradient: const LinearGradient(
begin: Alignment(0.98, -0.21),
end: Alignment(-0.98, 0.21),
colors: [
Color(0xFFD90B2E),
Color(0x60D90B2E)
],
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(30),
),
),
)
],
)))
],
),
),
),
sizedBoxHeight(40.h),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text20400white('Find your community'),
sizedBoxWidth(5.w),
Image.asset(
'assets/images/png/informationicon.png',
)
],
)),
sizedBoxHeight(10.w),
Center(
child: Container(
width: 108.w,
decoration: const ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1,
strokeAlign: BorderSide.strokeAlignCenter,
color: Color(0xFF858585),
),
),
),
),
),
sizedBoxHeight(30.h),
CustomTextFormField(
texttype: TextInputType.text,
hintText: "Search community",
leadingIcon:
// const Icon(Icons.mail_outline),
// SvgPicture.asset(
// // width: 23.w,
// // height: 23.h,
// 'assets/images/svg/search.svg',
// ),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: const Icon(
Icons.search,
size: 35,
color: Colors.white,
),
),
// validatorText: "Enter your full name",
inputFormatters: [
// LengthLimitingTextInputFormatter(20),
RemoveEmojiInputFormatter(),
],
onInput: (value) {
// Onboard().postGroupsearch({"search": value},
// streamController: searchcontroller);
// searchGroups(value!);
Getonboard().getCommunitysearch(value,
streamController: searchcontroller);
},
),
sizedBoxHeight(30.h),
StreamBuilder<GetcommunitiesModel>(
stream: searchcontroller.stream,
builder: (ctx, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
// Display shimmer effect while waiting for data
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
// Handle error state
return Center(
child: Text(
'${snapshot.error} occurred',
style: const TextStyle(fontSize: 18),
),
);
} else {
// Data has been loaded, show actual UI
return communitylistobj!.data!.isEmpty
? _buildNoDataBody(context)
: Expanded(
child: GridView.builder(
physics: const ScrollPhysics(),
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 12.0,
mainAxisSpacing: 12.0,
),
itemCount: communitylistobj!.data!.length,
itemBuilder: (context, index) {
return SizedBox(
height:
150.0, // Adjust this height according to your design
child: CommunitySelect(
titleString: communitylistobj!
.data![index].communityName!,
image: communitylistobj?.data?[index]
?.communityProfilePhoto ??
'',
index: communitylistobj!
.data![index].id!,
isSelected: _selectedIndices.contains(
communitylistobj!
.data![index].id!),
onTap: _onContainerTap,
),
);
},
),
);
}
},
),
// sizedBoxHeight(30),
CustomButton(
text: "Continue",
onPressed: () {
// Get.toNamed(RouteName.individualcommunitystep4);
if (_selectedIndices.isEmpty) {
utils.showToast('Please select activity');
} else {
print(_selectedIndices.toString());
// String selectedIndicesString =
// _selectedIndices.join(',');
// print(
// 'Selected Indices: [$selectedIndicesString]');
uploadata();
}
},
),
],
),
),
],
)),
);
}
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 CommunitySelect extends StatelessWidget {
final String titleString;
final String? image;
final int index;
final Function(int) onTap;
final bool isSelected;
CommunitySelect({
Key? key,
required this.titleString,
required this.image,
required this.index,
required this.onTap,
required this.isSelected,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
Container(
width: 73.w,
height: 73.h,
decoration: ShapeDecoration(
image: image == null || image!.isEmpty
? const DecorationImage(
image: AssetImage("assets/images/png/groupindividual2.png"),
fit: BoxFit.fill,
)
: DecorationImage(
image: NetworkImage(image!),
fit: BoxFit.fill,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
),
),
sizedBoxHeight(15.h),
Text(
titleString,
style: const TextStyle(
color: Colors.white,
fontSize: 12.0,
overflow: TextOverflow.ellipsis),
),
sizedBoxHeight(15.h),
GestureDetector(
onTap: () => onTap(index),
child: Container(
width: 169,
height: 23,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: const BorderSide(width: 1, color: Color(0xFFFF002B)),
borderRadius: BorderRadius.circular(30),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
isSelected
? const Text('Regrouping',
style: TextStyle(color: Colors.white, fontSize: 10.0))
: const Text('Join',
style: TextStyle(color: Colors.white, fontSize: 10.0))
],
),
),
),
]);
}
}