643 lines
26 KiB
Dart
643 lines
26 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:regroup/Common/CommonButton.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/sized_box.dart';
|
||
import 'package:regroup/Utils/dialogs.dart';
|
||
import 'package:regroup/Utils/texts.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';
|
||
|
||
int? _firstSelectedIndex;
|
||
bool _isFirstSelectionActive = false;
|
||
|
||
class SelectIndividualActivity extends StatefulWidget {
|
||
const SelectIndividualActivity({super.key});
|
||
|
||
@override
|
||
State<SelectIndividualActivity> createState() =>
|
||
_SelectIndividualActivityState();
|
||
}
|
||
|
||
class _SelectIndividualActivityState extends State<SelectIndividualActivity> {
|
||
final List<int> _selectedIndices = [];
|
||
TextEditingController otheractivitycontroller = TextEditingController();
|
||
|
||
// to select only two containers
|
||
// void _onContainerTap(int index) {
|
||
// setState(() {
|
||
// if (_selectedIndices.contains(index)) {
|
||
// _selectedIndices.remove(index);
|
||
// } else {
|
||
// if (_selectedIndices.length < 2) {
|
||
// _selectedIndices.add(index);
|
||
// } else {
|
||
// _selectedIndices[1] = index;
|
||
// }
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
void _onContainerTap(int index) {
|
||
setState(() {
|
||
if (_selectedIndices.contains(index)) {
|
||
_selectedIndices.remove(index);
|
||
if (_firstSelectedIndex == index) {
|
||
// If the first selected container is unselected, reset the active state
|
||
_firstSelectedIndex = null;
|
||
_isFirstSelectionActive = false;
|
||
}
|
||
} else {
|
||
if (_firstSelectedIndex == null) {
|
||
// The first item is being selected
|
||
_firstSelectedIndex = index;
|
||
_isFirstSelectionActive = true;
|
||
}
|
||
_selectedIndices.add(index);
|
||
}
|
||
});
|
||
}
|
||
|
||
Color _getGradientColor(int index) {
|
||
if (_selectedIndices.isEmpty) {
|
||
return Colors.transparent;
|
||
} else if (_firstSelectedIndex == index && _isFirstSelectionActive) {
|
||
// Apply Color(0XFFD90B2E) to the first selected item
|
||
return Color(0XFFD90B2E);
|
||
} else if (_selectedIndices.contains(index)) {
|
||
// Apply Color(0xFF009DAB) to all other selected items
|
||
return Color(0xFF009DAB);
|
||
}
|
||
return Colors.transparent;
|
||
}
|
||
|
||
// void _onContainerTap(int id) {
|
||
// setState(() {
|
||
// if (_selectedIndices.contains(id)) {
|
||
// _selectedIndices.remove(id);
|
||
// } else {
|
||
// _selectedIndices.add(id);
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// to give two different colors for selectedd two containers
|
||
// Color _getGradientColor(int index) {
|
||
// if (_selectedIndices.isEmpty) {
|
||
// return Colors.transparent;
|
||
// } else if (_selectedIndices.length == 1 &&
|
||
// _selectedIndices.contains(index)) {
|
||
// return Color(0XFFD90B2E);
|
||
// } else if (_selectedIndices.length == 2) {
|
||
// if (_selectedIndices[0] == index) {
|
||
// return Color(0XFFD90B2E);
|
||
// } else if (_selectedIndices[1] == index) {
|
||
// return Color(0xFF009DAB);
|
||
// }
|
||
// }
|
||
// return Colors.transparent;
|
||
// }
|
||
|
||
// Color _getGradientColor(int id) {
|
||
// if (_selectedIndices.contains(id)) {
|
||
// return const Color(0XFFD90B2E); // Selected color
|
||
// }
|
||
// return Colors.transparent; // Default color
|
||
// }
|
||
|
||
Uploadata() async {
|
||
utils.loader();
|
||
String selectedIndicesString = '[${_selectedIndices.join(',')}]';
|
||
print('Selected Indices: $selectedIndicesString');
|
||
Map<String, dynamic> updata = {
|
||
"manage_interest_xid": selectedIndicesString,
|
||
"other_interest": otheractivitycontroller.text,
|
||
};
|
||
print('Payload: $updata');
|
||
|
||
final data = await Onboard().PostIndividualActivity(updata);
|
||
if (data.status == ResponseStatus.SUCCESS) {
|
||
Get.back();
|
||
print("Activities selected");
|
||
// Get.toNamed(RouteName.individualgroupstep3);
|
||
Get.toNamed(RouteName.findcommunitypage);
|
||
|
||
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),
|
||
bottomNavigationBar: Padding(
|
||
padding: const EdgeInsets.only(bottom: 10, left: 16, right: 16),
|
||
child: CustomButton(
|
||
text: "Continue",
|
||
onPressed: () {
|
||
if (_selectedIndices.isEmpty &&
|
||
otheractivitycontroller.text.isEmpty) {
|
||
utils.showToast('Please select activity');
|
||
} else {
|
||
print(_selectedIndices.toString());
|
||
// String selectedIndicesString =
|
||
// _selectedIndices.join(',');
|
||
// print(
|
||
// 'Selected Indices: [$selectedIndicesString]');
|
||
Uploadata();
|
||
}
|
||
// Get.toNamed(
|
||
// RouteName.individualgroupstep3);
|
||
}),
|
||
),
|
||
body: SafeArea(
|
||
child: FutureBuilder(
|
||
future: Getonboard().getIndividualactivity(),
|
||
builder: (ctx, snapshot) {
|
||
if (snapshot.data == null) {
|
||
return const Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [Center(child: CircularProgressIndicator())],
|
||
);
|
||
}
|
||
if (snapshot.connectionState == ConnectionState.done) {
|
||
if (snapshot.hasError) {
|
||
return Center(
|
||
child: Text(
|
||
'${snapshot.error} occured',
|
||
style: TextStyle(fontSize: 18.spMin),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
return 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: 0.h),
|
||
child: SingleChildScrollView(
|
||
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 1 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: [
|
||
Container(
|
||
width: 100.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),
|
||
indiactivityobj!.data == null ||
|
||
indiactivityobj!.data!.isEmpty
|
||
? _buildNoDataBody(context)
|
||
: Column(
|
||
crossAxisAlignment:
|
||
CrossAxisAlignment.center,
|
||
children: [
|
||
text20400white(
|
||
'What are your interests?'),
|
||
// sizedBoxHeight(5.w),
|
||
|
||
_isFirstSelectionActive
|
||
? text13400A7A7A7(
|
||
'Select your secondary interests')
|
||
: text13400A7A7A7(
|
||
'Select your primary interest'),
|
||
|
||
// Container(
|
||
// width: 154.w,
|
||
// decoration: const ShapeDecoration(
|
||
// shape: RoundedRectangleBorder(
|
||
// side: BorderSide(
|
||
// width: 1,
|
||
// strokeAlign:
|
||
// BorderSide.strokeAlignCenter,
|
||
// color: Color(0xFF858585),
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// ),
|
||
sizedBoxHeight(30.h),
|
||
GridView.builder(
|
||
physics: const ScrollPhysics(),
|
||
shrinkWrap: true,
|
||
gridDelegate:
|
||
SliverGridDelegateWithFixedCrossAxisCount(
|
||
crossAxisCount:
|
||
3, // Number of items in each row
|
||
crossAxisSpacing: 12
|
||
.w, // Horizontal spacing between items
|
||
mainAxisSpacing: 12
|
||
.h, // Vertical spacing between items
|
||
),
|
||
itemCount:
|
||
indiactivityobj!.data!.length,
|
||
itemBuilder: (context, index) {
|
||
return ActivityContainer(
|
||
index: indiactivityobj!
|
||
.data![index].id!,
|
||
titleString: indiactivityobj!
|
||
.data![index].name!,
|
||
image: indiactivityobj!
|
||
.data![index].image,
|
||
// 'assets/images/svg/individualact7.svg',
|
||
isSelected: _selectedIndices
|
||
.contains(indiactivityobj!
|
||
.data![index].id!),
|
||
gradientColor: _getGradientColor(
|
||
indiactivityobj!
|
||
.data![index].id!),
|
||
onTap: _onContainerTap,
|
||
);
|
||
},
|
||
),
|
||
|
||
sizedBoxHeight(30.h),
|
||
// text20400FCFCFC("Add other activity"),
|
||
// sizedBoxHeight(25.h),
|
||
// CustomTextFormField(
|
||
// textEditingController:
|
||
// otheractivitycontroller,
|
||
// texttype: TextInputType.text,
|
||
// hintText: "Enter other activity",
|
||
// // leadingIcon:
|
||
// // // const Icon(Icons.mail_outline),
|
||
// // Image.asset(
|
||
// // width: 22.w,
|
||
// // height: 17.h,
|
||
// // 'assets/images/png/user.png',
|
||
// // ),
|
||
// // validatorText: "Enter your full name",
|
||
// validator: (value) {
|
||
// if (value!.isEmpty) {
|
||
// return 'Enter your full name ';
|
||
// }
|
||
// return null;
|
||
// },
|
||
// inputFormatters: [
|
||
// // LengthLimitingTextInputFormatter(20),
|
||
// RemoveEmojiInputFormatter(),
|
||
// FilteringTextInputFormatter.allow(
|
||
// RegExp('[a-zA-Z ]'))
|
||
// ],
|
||
// ),
|
||
|
||
sizedBoxHeight(35.h),
|
||
],
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
),
|
||
),
|
||
floatingActionButton: Stack(
|
||
alignment: Alignment.center,
|
||
clipBehavior: Clip.none, // Ensure the Positioned widget is visible
|
||
children: [
|
||
FloatingActionButton(
|
||
onPressed: () {
|
||
interestdialogwidget();
|
||
},
|
||
backgroundColor: const Color(0xFFD90B2E),
|
||
autofocus: true,
|
||
shape: const CircleBorder(),
|
||
child: Icon(
|
||
Icons.add,
|
||
color: Colors.white,
|
||
size: 27.sp,
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 60.w,
|
||
child: Container(
|
||
width: 212.w,
|
||
height: 35.h,
|
||
decoration: BoxDecoration(
|
||
color: Color(0xFF363636),
|
||
borderRadius: BorderRadius.circular(20),
|
||
border:
|
||
Border.all(color: Color(0xFFD90B2E), width: 1.w)),
|
||
child: Center(
|
||
child: text16400white("Can’t find your interest"))),
|
||
)
|
||
],
|
||
),
|
||
));
|
||
}
|
||
|
||
Widget _buildNoDataBody(context) {
|
||
return const Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [Text("No Data Found")],
|
||
);
|
||
}
|
||
}
|
||
|
||
interestdialogwidget() {
|
||
Get.dialog(Dialog(
|
||
// backgroundColor: Colors.transparent,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(10.r),
|
||
color: const Color(0xFF222935)),
|
||
child: Padding(
|
||
padding: EdgeInsets.only(
|
||
right: 16.w, left: 16.w, top: 20.h, bottom: 40.h),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Spacer(),
|
||
Image.asset(
|
||
"assets/images/png/x-circle.png",
|
||
height: 28.h,
|
||
width: 28.w,
|
||
)
|
||
],
|
||
),
|
||
text16w700_FCFCFC("Suggest interest"),
|
||
sizedBoxHeight(16.h),
|
||
Center(
|
||
child: CustomTextFormField(
|
||
hintText: "Please type your interest",
|
||
)),
|
||
sizedBoxHeight(10.h),
|
||
text10w400_FCFCFC_blur("We will surely make this happen"),
|
||
sizedBoxHeight(20.h),
|
||
Align(
|
||
alignment: Alignment.center,
|
||
child: SizedBox(
|
||
width: 177.w,
|
||
child: CommonBtn(
|
||
text: "Suggest",
|
||
onTap: () {
|
||
Get.back();
|
||
thankdialogwidget();
|
||
})),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
));
|
||
}
|
||
|
||
thankdialogwidget() {
|
||
Get.dialog(Dialog(
|
||
// backgroundColor: Colors.transparent,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(10.r),
|
||
color: const Color(0xFF222935)),
|
||
child: Padding(
|
||
padding: EdgeInsets.only(
|
||
right: 16.w, left: 16.w, top: 20.h, bottom: 40.h),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Spacer(),
|
||
Image.asset(
|
||
"assets/images/png/x-circle.png",
|
||
height: 28.h,
|
||
width: 28.w,
|
||
)
|
||
],
|
||
),
|
||
Image.asset(
|
||
"assets/images/png/correct 1.png",
|
||
height: 72.h,
|
||
width: 72.w,
|
||
),
|
||
sizedBoxHeight(20.h),
|
||
text16w700_FCFCFC(
|
||
"Thank You! \n for adding one more to the club",
|
||
textAlign: TextAlign.center),
|
||
sizedBoxHeight(16.h),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
));
|
||
}
|
||
|
||
class ActivityContainer extends StatelessWidget {
|
||
final int index;
|
||
final String titleString;
|
||
final String? image;
|
||
final bool isSelected;
|
||
final Color gradientColor;
|
||
final Function(int) onTap;
|
||
|
||
ActivityContainer({
|
||
required this.index,
|
||
required this.titleString,
|
||
required this.image,
|
||
required this.isSelected,
|
||
required this.gradientColor,
|
||
required this.onTap,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return GestureDetector(
|
||
onTap: () => onTap(index),
|
||
child: Container(
|
||
// width: 110.w,
|
||
// height: 120.h,
|
||
decoration: ShapeDecoration(
|
||
gradient: LinearGradient(
|
||
begin: const Alignment(0.98, -0.21),
|
||
end: const Alignment(-0.98, 0.21),
|
||
colors: isSelected
|
||
? _firstSelectedIndex == index &&
|
||
_isFirstSelectionActive == true
|
||
? [
|
||
gradientColor.withOpacity(0.80),
|
||
gradientColor.withOpacity(0.77),
|
||
Color(0xFF009DAB).withOpacity(0.66),
|
||
Color(0xFF009DAB).withOpacity(0.18),
|
||
]
|
||
: [
|
||
Colors.white.withOpacity(0.06),
|
||
Colors.white.withOpacity(0.08),
|
||
]
|
||
: [
|
||
Colors.white.withOpacity(0.06),
|
||
Colors.white.withOpacity(0.08),
|
||
],
|
||
),
|
||
shape: RoundedRectangleBorder(
|
||
side: isSelected
|
||
? _firstSelectedIndex == index &&
|
||
_isFirstSelectionActive == true
|
||
? BorderSide(width: 1.w, color: Color(0xFF434A53))
|
||
: BorderSide(width: 3.w, color: gradientColor)
|
||
: BorderSide(width: 3.w, color: gradientColor),
|
||
|
||
|
||
borderRadius: BorderRadius.circular(10),
|
||
),
|
||
),
|
||
child: Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 0.w, vertical: 10.h),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [
|
||
// image.isEmpty
|
||
// ? SvgPicture.asset(
|
||
// "assets/images/svg/individualact7.svg",
|
||
// width: 50.w,
|
||
// height: 50.h,
|
||
// )
|
||
// : Image.network(image),
|
||
image == null || image!.isEmpty
|
||
? Image.asset(
|
||
'assets/images/png/redregroup.png',
|
||
color: Colors.white,
|
||
width: 50.w,
|
||
height: 50.h,
|
||
)
|
||
// SvgPicture.asset(
|
||
// "assets/images/svg/individualact7.svg",
|
||
// width: 50.w,
|
||
// height: 50.h,
|
||
// )
|
||
: Image.network(
|
||
image!,
|
||
width: 50.w,
|
||
height: 50.h,
|
||
),
|
||
const Spacer(flex: 3),
|
||
SizedBox(
|
||
child: Text(
|
||
titleString,
|
||
style: TextStyle(
|
||
fontSize: 14.sp,
|
||
color: Colors.white,
|
||
fontWeight: FontWeight.w400,
|
||
),
|
||
textAlign: TextAlign.center,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|