Files
Regroup/lib/onboarding/Signup/View/Individual/step3Selectyourgroup.dart

448 lines
19 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/GroupModel.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 SelectIndividualGroup extends StatefulWidget {
const SelectIndividualGroup({super.key});
@override
State<SelectIndividualGroup> createState() => _SelectIndividualGroupState();
}
class _SelectIndividualGroupState extends State<SelectIndividualGroup> {
StreamController<GrouplistModel> searchcontroller = StreamController();
@override
void initState() {
var updata = "";
Getonboard().getGroupsearch(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_group_xid": selectedIndicesString,
};
print('Payload: $updata');
final data = await Onboard().postGroups(updata);
if (data.status == ResponseStatus.SUCCESS) {
Get.back();
print("groups selected");
Get.toNamed(RouteName.individualcommunitystep4);
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: Color.fromARGB(255, 18, 32, 47),
bottomNavigationBar: Padding(
padding: const EdgeInsets.only(bottom: 10, left: 16, right: 16),
child: 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();
}
},
),
),
body: Stack(
children: [
Positioned(top: 70, left: -30, child: CommonBlurLeftSecond()),
Positioned(top: 400, right: -30, child: CommonBlurRightSecond()),
Positioned(top: 630, left: -30, child: CommonBlurLeftBlue()),
SingleChildScrollView(
child: GlassmorphicContainer(
width: MediaQuery.of(context).size.width,
height:
// 500.h,
MediaQuery.of(context).size.height,
borderRadius: 2,
blur: 6,
alignment: Alignment.bottomLeft,
border: 2,
linearGradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0XFF222935).withOpacity(0.60),
Color(0XFF222935).withOpacity(0.60),
Color(0XFF222935).withOpacity(0.60),
Color(0XFF222935).withOpacity(0.60),
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
],
),
borderGradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
// Color.fromARGB(255, 18, 32, 47).withOpacity(0.50),
Color(0XFF222935).withOpacity(0.60),
Color(0XFF222935).withOpacity(0.60),
],
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.w, vertical: 50.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 2 of 3')),
sizedBoxHeight(20.h),
Container(
width: double.infinity,
height: 25.h,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1, color: Color(0xFF434A53)),
borderRadius: BorderRadius.circular(30),
),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 2.h),
child: Row(
children: [
Container(
width: 216.w,
height: 15.h,
decoration: ShapeDecoration(
gradient: 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: 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 group'),
sizedBoxWidth(5.w),
Image.asset(
'assets/images/png/informationicon.png')
],
)),
sizedBoxHeight(10.w),
Center(
child: Container(
width: 108.w,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1,
strokeAlign: BorderSide.strokeAlignCenter,
color: Color(0xFF858585),
),
),
),
),
),
sizedBoxHeight(30.h),
CustomTextFormField(
// textEditingController: searchcontroller,
texttype: TextInputType.text,
hintText: "Search groups",
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: 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().getGroupsearch(value,
streamController: searchcontroller);
},
),
sizedBoxHeight(30.h),
StreamBuilder<GrouplistModel>(
stream: searchcontroller.stream,
builder: (ctx, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
// Display shimmer effect while waiting for data
return Center(
child: CircularProgressIndicator());
} else if (snapshot.hasError) {
// Handle error state
return Center(
child: Text(
'${snapshot.error} occurred',
style: TextStyle(fontSize: 18),
),
);
} else {
// Data has been loaded, show actual UI
return grouplistobj!.data!.isEmpty
? _buildNoDataBody(context)
: Expanded(
child: GridView.builder(
physics: ScrollPhysics(),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 12.0,
mainAxisSpacing: 12.0,
),
itemCount: grouplistobj!.data!.length,
itemBuilder: (context, index) {
return SizedBox(
height:
150.0, // Adjust this height according to your design
child: GroupSelect(
titleString: grouplistobj!
.data![index].title!,
image: grouplistobj
?.data?[index]
?.groupImage ??
'',
index: grouplistobj!
.data![index].id!,
isSelected: _selectedIndices
.contains(grouplistobj!
.data![index].id!),
onTap: _onContainerTap,
),
);
},
),
);
}
},
),
],
),
)),
),
],
)),
);
}
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 GroupSelect extends StatelessWidget {
final String titleString;
final String? image;
final int index;
final Function(int) onTap;
final bool isSelected;
GroupSelect({
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.start, children: [
Container(
width: 169,
height: 74,
decoration: ShapeDecoration(
image: image == null || image!.isEmpty
? DecorationImage(
image: AssetImage("assets/images/png/groupindividual3.png"),
fit: BoxFit.fill,
)
: DecorationImage(
image: NetworkImage(image!),
fit: BoxFit.fill,
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
),
),
SizedBox(height: 15.0),
Text(
titleString,
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
overflow: TextOverflow.ellipsis),
),
SizedBox(height: 15.0),
GestureDetector(
onTap: () => onTap(index),
child: Container(
width: 169,
height: 23,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: Color(0xFFFF002B)),
borderRadius: BorderRadius.circular(30),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
isSelected
? Text('Regrouping',
style: TextStyle(color: Colors.white, fontSize: 10.0))
: Text('Join',
style: TextStyle(color: Colors.white, fontSize: 10.0))
],
),
),
),
]);
}
}