import 'dart:async'; import 'dart:developer'; import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart' hide MultipartFile, FormData; import 'package:regroup/Common/CommonButton.dart'; import 'package:regroup/Common/CommonGlassmorphism.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/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/resources/routes/route_name.dart'; import 'package:path/path.dart' as path; import 'package:regroup/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/view_model/getmethod.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/view_model/postmethod.dart'; class AddGroup extends StatefulWidget { const AddGroup({super.key}); @override State createState() => _AddGroupState(); } class _AddGroupState extends State { List isCheckedList = [false, false, false, false].obs; List groupData = [ { "imagePath": "assets/images/png/img45.png", "title": "Iron titans fitness crew", "subtitle": "Lorem ipsum dummy text", }, { "imagePath": "assets/images/png/Rectangle 25.png", "title": "Body blitz brigade", "subtitle": "Lorem ipsum dummy text", }, { "imagePath": "assets/images/png/img2.png", "title": "Fit fusion squad", "subtitle": "Lorem ipsum dummy text", }, { "imagePath": "assets/images/png/img2.png", "title": "Power pulse posse", "subtitle": "Lorem ipsum dummy text", }, ]; int communitytype = Get.arguments["communitytype"]; int activitytype = Get.arguments["activityid"]; String communityname = Get.arguments["communityname"]; String communitylocation = Get.arguments["communitylocation"]; String communitydescription = Get.arguments["communitydescription"]; List filepath = Get.arguments['communityprofilephoto']; List bannerPath = Get.arguments['communitybannerimage']; StreamController searchcontroller = StreamController(); @override void initState() { var updata = ""; Getcommunity() .getCommunityAddGroupsearch(updata, streamController: searchcontroller); super.initState(); } @override void dispose() { searchcontroller.close(); super.dispose(); } final List _selectedIndices = []; void _onContainerTap(int id) { setState(() { if (_selectedIndices.contains(id)) { _selectedIndices.remove(id); } else { _selectedIndices.add(id); } }); } Uploadata() async { utils.loader(); List bannermedialist = []; List profielpicturelist = []; for (var file in bannerPath.where((file) => file != null)) { bannermedialist.add( await MultipartFile.fromFile( file!.path, filename: path.basename(file.path), ), ); } for (var file in filepath.where((file) => file != null)) { profielpicturelist.add( await MultipartFile.fromFile( file!.path, filename: path.basename(file.path), ), ); } String selectedIndicesString = '[${_selectedIndices.join(',')}]'; print('Selected Indices: $selectedIndicesString'); FormData formdata = FormData.fromMap({ "community_profile_photo": profielpicturelist[0], "community_banner_image": bannermedialist[0], "community_name": communityname, "community_location": communitylocation, "community_description": communitydescription, 'community_type_xid': communitytype, 'activity_xid': activitytype, 'manage_groups_xid': selectedIndicesString.isEmpty ? null : selectedIndicesString, }); print('updata is ${formdata.toString()}'); log('log is ${formdata.toString()}'); final data = await PostMethodCommunity().postCreatecommunity(formdata); if (data.status == ResponseStatus.SUCCESS) { Get.back(); print("community created"); // Get.toNamed(RouteName.mycommunity); Get.back(); Get.back(); return utils.showToast(data.message); } else { Get.back(); print("community not created"); return utils.showToast(data.message); } } @override Widget build(BuildContext context) { return Scaffold( // key: _scaffoldKey1, backgroundColor: Color(0xFF222935), extendBody: true, appBar: CommonAppbar( titleTxt: "Add groups", ), resizeToAvoidBottomInset: false, bottomNavigationBar: Padding( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.h), child: CustomButton( text: "Add", onPressed: () { // Get.toNamed(RouteName.mycommunity); print('selected groups are ${_selectedIndices.toString()}'); Uploadata(); }, ), ), body: Stack(children: [ Container( decoration: const BoxDecoration( image: DecorationImage( image: AssetImage("assets/images/png/Ellipse 1496.png"), fit: BoxFit.fill)), ), SingleChildScrollView( child: Column(children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 16.w), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ sizedBoxHeight(20.h), 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 groups", onInput: (value) { Getcommunity().getCommunityAddGroupsearch(value, streamController: searchcontroller); }, ), sizedBoxHeight(25.h), // Row( // children: [ // commonGlassUI( // opacity1: 0.24, // opacity2: 0.24, // width: 50.w, // height: 50.h, // borderRadius: BorderRadius.circular( 100), // customWidget: Center( // child: Image.asset( // "assets/images/png/Black.png", // height: 30.h, // width: 30.w, // )), // borderwidth: 0.5), // sizedBoxWidth(8.w), // text18w400_FCFCFC("Create group"), // Spacer(), // Icon( // Icons.arrow_forward_ios_outlined, // color: Colors.white, // size: 14.sp, // ), // ], // ), // sizedBoxHeight(25.h), sizedBoxHeight(30.h), text18w700white("Existing Groups"), sizedBoxHeight(20.h), ]), ), StreamBuilder( stream: searchcontroller.stream, builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ CircularProgressIndicator(), ], ), ); } else if (snapshot.hasError) { return Center( child: Text( '${snapshot.error} occured', style: TextStyle(fontSize: 18.sp), ), ); } else { return communityaddgroupobj!.data.isEmpty ? _buildNoDataBody(context) : ListView.builder( shrinkWrap: true, physics: ScrollPhysics(), itemCount: communityaddgroupobj!.data.length, itemBuilder: (context, index) { final isChecked = _selectedIndices.contains( communityaddgroupobj!.data[index].id!); return Column( children: [ groupWidget( index: communityaddgroupobj!.data[index].id!, imagePath: communityaddgroupobj! .data[index].groupImage ?? '', title: communityaddgroupobj! .data[index].title!, subtitle: communityaddgroupobj! .data[index].description!, isChecked: isChecked, // isCheckedList[index], onCheckedChanged: (bool? value) { // isCheckedList[index] = value ?? false; _onContainerTap(communityaddgroupobj! .data[index].id!); }, ), commonDivider(), ], ); }, ); } }), sizedBoxHeight(50.h), ]), ) ])); } Widget _buildNoDataBody(context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "No Groups Found", style: TextStyle( color: Colors.white, fontSize: 16.sp, fontWeight: FontWeight.w600), ) ], ), ); } Widget groupWidget({ required int index, required String? imagePath, required String? title, required String? subtitle, required bool isChecked, required ValueChanged onCheckedChanged, }) { return Padding( padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 16.w), child: Row( children: [ imagePath == null || imagePath.isEmpty ? CircleAvatar( backgroundImage: AssetImage('assets/images/png/img2.png'), radius: 20.r, ) : // CircleAvatar( // backgroundImage: NetworkImage(imagePath), // radius: 20.r, // ), CircleAvatar( backgroundImage: CachedNetworkImageProvider(imagePath), radius: 20.r, child: CachedNetworkImage( cacheKey: index.toString(), maxHeightDiskCache: 100, maxWidthDiskCache: 100, imageUrl: imagePath, placeholder: (context, url) => Container(), errorWidget: (context, url, error) => Icon(Icons.error), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25.r, ), ), ), sizedBoxWidth(10.w), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ title == null || title.isEmpty ? text16w400_FCFCFC('ReGroup') : Text( title, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 16.sp, color: const Color(0xFFFCFCFC), fontFamily: 'Helvetica', fontWeight: FontWeight.w400), ), sizedBoxHeight(4.h), subtitle == null || subtitle.isEmpty ? text12w400_FCFCFC_blur('ReGroup') : Text( subtitle, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12.sp, color: const Color(0xFFFCFCFC).withOpacity(0.8), fontFamily: 'Helvetica', fontWeight: FontWeight.w400), ), ], ), ), Spacer(), commonGlassUI( borderwidth: isChecked ? 1.2 : 0.9, borderRadius: BorderRadius.circular(2), height: 23.h, width: 23.w, opacity1: 0.24, opacity2: 0.24, borderColor: isChecked ? Color(0xFFD90B2E) : Color(0xFF434A53), customWidget: Transform.scale( scale: 1, child: Checkbox( side: BorderSide(color: Colors.transparent), value: isChecked, activeColor: Colors.transparent, checkColor: Color(0xFFD90B2E), onChanged: onCheckedChanged, ), ), ), ], ), ); } }