From 01a8e0d908d344c23d46c4fb377ebc1843ef90dd Mon Sep 17 00:00:00 2001 From: Shubhamshirva Date: Wed, 14 Aug 2024 20:43:43 +0530 Subject: [PATCH 1/2] get api called for edit commiunity page,and some fixes --- lib/Common/api_urls.dart | 3 + lib/Utils/Helper.dart | 15 + .../Community settings/CommunitySetting.dart | 8 +- .../EditCommunity/EditCommunity.dart | 777 ++++++++++++------ .../Community/Members/CommunityMembers.dart | 6 +- .../Model/communityMebersModel.dart | 3 + .../Model/communityeditpageModel.dart | 185 +++++ .../Community/MyCommunity/NewCommunity.dart | 4 +- .../MyCommunity/View/CommunityDetails.dart | 4 +- .../MyCommunity/view_model/getmethod.dart | 14 + pubspec.lock | 4 +- 11 files changed, 766 insertions(+), 257 deletions(-) create mode 100644 lib/sidemenu/Community/MyCommunity/Model/communityeditpageModel.dart diff --git a/lib/Common/api_urls.dart b/lib/Common/api_urls.dart index cf863d9..580b48f 100644 --- a/lib/Common/api_urls.dart +++ b/lib/Common/api_urls.dart @@ -168,6 +168,9 @@ class ApiUrls { static const getcommunitymembers = "${baseUrl}fetch-community-all-members"; + static const geteditcommunity = "${baseUrl}edit-community"; + + } diff --git a/lib/Utils/Helper.dart b/lib/Utils/Helper.dart index 7424236..6e5f658 100644 --- a/lib/Utils/Helper.dart +++ b/lib/Utils/Helper.dart @@ -66,4 +66,19 @@ class Helper { ); } } + + static Future networkImageToFile(String imageUrl) async { + Dio dio = Dio(); + Response response = await dio.get(imageUrl, + options: Options(responseType: ResponseType.bytes)); + + final directory = await getTemporaryDirectory(); + final filePath = '${directory.path}/${imageUrl.split('/').last}'; + + final file = File(filePath); + await file.writeAsBytes(response.data!); + + return file; +} + } diff --git a/lib/sidemenu/Community/Admin/PopupItem/Community settings/CommunitySetting.dart b/lib/sidemenu/Community/Admin/PopupItem/Community settings/CommunitySetting.dart index 37e4aa1..0f0e2a2 100644 --- a/lib/sidemenu/Community/Admin/PopupItem/Community settings/CommunitySetting.dart +++ b/lib/sidemenu/Community/Admin/PopupItem/Community settings/CommunitySetting.dart @@ -16,6 +16,8 @@ class CommunitySetting extends StatefulWidget { } class _CommunitySettingState extends State { + + int communityid = Get.arguments['communityid']; @override Widget build(BuildContext context) { return Scaffold( @@ -37,7 +39,11 @@ class _CommunitySettingState extends State { sizedBoxHeight(30.h), GestureDetector( onTap: () { - Get.toNamed(RouteName.editcommunity); + Get.toNamed(RouteName.editcommunity, + arguments: { + 'communityid' : communityid, + } + ); }, child: rowTile(text: 'Edit community info')), commonDivider(), diff --git a/lib/sidemenu/Community/Admin/PopupItem/Community settings/EditCommunity/EditCommunity.dart b/lib/sidemenu/Community/Admin/PopupItem/Community settings/EditCommunity/EditCommunity.dart index 8d4485a..4e23501 100644 --- a/lib/sidemenu/Community/Admin/PopupItem/Community settings/EditCommunity/EditCommunity.dart +++ b/lib/sidemenu/Community/Admin/PopupItem/Community settings/EditCommunity/EditCommunity.dart @@ -1,18 +1,27 @@ +import 'dart:developer'; import 'dart:io'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:regroup/Common/CommonDropDown.dart'; +import 'package:get/get.dart'; import 'package:regroup/Common/CommonGlassmorphism.dart'; +import 'package:regroup/Common/base_manager.dart'; +import 'package:regroup/Main_Screens/ProfileTab/EditProfile/Model/InterestModel.dart' + as primaryactlist; import 'package:regroup/Utils/Common/CommonAppbar.dart'; import 'package:regroup/Utils/Common/CommonDropdown.dart'; import 'package:regroup/Utils/Common/CustomNextButton.dart'; import 'package:regroup/Utils/Common/ImageUpload.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; +import 'package:regroup/Utils/Helper.dart'; +import 'package:regroup/Utils/dialogs.dart'; import 'package:regroup/Utils/texts.dart'; import 'package:regroup/Utils/Common/CustomTextformfield.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/view_model/getmethod.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart'; +import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart'; class EditCommunity extends StatefulWidget { const EditCommunity({super.key}); @@ -24,12 +33,19 @@ class EditCommunity extends StatefulWidget { class _EditCommunityState extends State { TextEditingController communitynameController = TextEditingController(); TextEditingController descriptionController = TextEditingController(); + TextEditingController locationcontroller = TextEditingController(); + TextEditingController websitelinkcontroller = TextEditingController(); + + late Future myfuture; + int communityid = Get.arguments['communityid']; @override void initState() { - communitynameController.text = 'Active alliance network'; - descriptionController.text = - "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer ."; + myfuture = Getcommunity().getCommunityeditpage(communityid); + // communitynameController.text = 'Active alliance network'; + // descriptionController.text = + // "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer ."; + super.initState(); } @@ -37,6 +53,93 @@ class _EditCommunityState extends State { List bannerPath = []; bool isImageAdded = false; bool isbannerAdded = false; + String? bannerimage; + bool isBannerLoaded = false; + bool isactivityLoaded = false; + + Future _loadBannerImage() async { + if (bannerimage!.isNotEmpty) { + File bannerFile = await Helper.networkImageToFile(bannerimage!); + setState(() { + bannerPath.add(bannerFile); + isbannerAdded = true; + isBannerLoaded = true; + }); + } + } + + bool isValidWebBannerLink(String link) { + RegExp urlRegExp = RegExp( + r"^(http(s)?://)?" + r"((([a-zA-Z0-9-]+)\.)+[a-zA-Z]{2,}|" + r"((\d{1,3}\.){3}\d{1,3}))" + r"(:\d{1,5})?(/([a-zA-Z0-9-._?,'+&%\$#=~])*)?$", + ); + + return urlRegExp.hasMatch(link); + } + + final Map _typeCommunityMap = { + 'Public': 1, + 'Private - Request to join': 2, + 'Secret': 3, + }; + + String _selectedtypecommunity = ''; + + void _onItemSelected(String value) { + setState(() { + _selectedtypecommunity = value; + print('selected community is $_selectedtypecommunity'); + }); + } + + primaryactlist.InterestModel? abilityModel; + List activity = []; + List _activitydrop = []; + + String? selectedActivityName; + + Future fetchActivitylist() async { + PrimaryActivityListApi abilityListAPI = PrimaryActivityListApi(); + ResponseData response = await abilityListAPI.getActivitylistApi(); + + if (response.status == ResponseStatus.SUCCESS) { + abilityModel = primaryactlist.InterestModel.fromJson(response.data!); + setState(() { + activity = abilityModel!.data ?? []; + _activitydrop = + activity.map((platform) => platform.name.toString()).toList(); + }); + + // Ensure dropdown list updates after setting the initial value + setState(() { + // Set the initial selected activity if data is available + int activitiesXids = + communityeditobj!.data!.communityData!.activityData!.id!; + selectedactivityid = activitiesXids; + selectedActivityName = activity + .firstWhere((item) => item.id == activitiesXids, + orElse: () => activity.first) + .name; + isactivityLoaded = true; + }); + log(activity.toString()); + } else { + print('Failed to fetch abilities'); + } + } + + int? selectedactivityid; + + void getCatIdFromName(String selectedAbility) { + selectedactivityid = activity + .firstWhere((item) => item.name == selectedAbility, + orElse: () => activity.first) + .id; + print('Selected activity ID is $selectedactivityid'); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -47,261 +150,441 @@ class _EditCommunityState extends State { titleTxt: "Edit community info", ), resizeToAvoidBottomInset: false, - body: Stack(children: [ - Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/png/Ellipse 1496.png"), - fit: BoxFit.fill)), - ), - SingleChildScrollView( - child: Column(children: [ - sizedBoxHeight(30.h), - Stack( - clipBehavior: Clip.none, + body: FutureBuilder( + future: myfuture, + builder: (ctx, snapshot) { + if (snapshot.data == null) { + return const Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, children: [ - Container( - height: 100.h, - width: 100.w, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: - Border.all(color: Color(0xFF434A53), width: 0.5.w), + Center( + child: CircularProgressIndicator( + color: Color(0xFFC18948), ), - child: Center( - child: filePath.isNotEmpty - ? ClipOval( - child: SizedBox.fromSize( - size: Size.fromRadius(50.r), - child: Image.file( - filePath[0]!, - fit: BoxFit.cover, - width: double.infinity, - ), - ), - ) - : Image.asset('assets/images/png/Ellipse 37.png', - fit: BoxFit.cover), - ), - ), - Positioned( - right: -10, - bottom: 0, - child: InkWell( - onTap: () { - ImageUploadBottomSheet().showModal( - context, - true, - (result) { - var file = File(result); - - filePath.add(file); - isImageAdded = true; - setState(() {}); - }, - ); - }, - child: Container( - height: 35.h, - width: 35.w, - decoration: BoxDecoration( - color: Color(0xFFD90B2E), - shape: BoxShape.circle, - border: Border.all( - color: Color(0xFFD90B2E), width: 0.5.w)), - child: Center( - child: Image.asset( - 'assets/images/png/cameraicon.png', - height: 14.h, - width: 15.w, - ), - ), - ), - )) + ) ], - ), - sizedBoxHeight(25.h), - text16w400_white("Edit community profile picture"), - sizedBoxHeight(30.h), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC("Community banner image"), - sizedBoxHeight(16.h), - GestureDetector( - onTap: () { - ImageUploadBottomSheet().showModal( - context, - false, - (result) { - var file = File(result); + ); + } + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occured', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + } + if (!isBannerLoaded) { + bannerimage = + communityeditobj!.data!.communityData!.communityBannerImage!; + _loadBannerImage(); // Call only if not already loaded + } + communitynameController.text = + communityeditobj!.data!.communityData!.communityName!; + descriptionController.text = + communityeditobj!.data!.communityData!.communityDescription!; + locationcontroller.text = + communityeditobj!.data!.communityData!.communityLocation!; + websitelinkcontroller.text = + communityeditobj!.data!.communityData!.communityDescription!; + var communityType = + communityeditobj!.data!.communityData!.communityTypeData!.name; + if (_selectedtypecommunity.isEmpty) { + _selectedtypecommunity = communityType ?? 'Public'; + } + if (!isactivityLoaded) { + fetchActivitylist(); + } - bannerPath.add(file); - isbannerAdded = true; - setState(() {}); - }, - ); - }, - child: DottedBorder( - strokeWidth: 1, - dashPattern: [7, 4], - borderType: BorderType.RRect, - radius: Radius.circular(14.r), - color: Color(0xFF434A53), - child: commonGlassUI( - borderwidth: 0, - width: double.infinity, - height: 150.h, - borderRadius: BorderRadius.circular( 10.r), - customWidget: bannerPath.isNotEmpty && isbannerAdded - ? Stack(children: [ - Image.file( - bannerPath[0]!, - fit: BoxFit.cover, - width: double.infinity, - ), - Positioned( - right: 5, - bottom: 5, - child: GestureDetector( - onTap: () { - bannerPath.clear(); - isbannerAdded = false; - setState(() {}); - }, - child: Container( - width: 27, - height: 27, - decoration: ShapeDecoration( - color: Color(0xFF7E7E7E), - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(5)), - ), - child: Icon( - Icons.delete_outline_outlined, - color: Colors.white, - ))), - ), - ]) - : Padding( - padding: EdgeInsets.symmetric(vertical: 16.h), - child: Column( - children: [ - Image.asset( - "assets/images/png/cameraicon2.png", - height: 36.h, - width: 36.w, - ), - sizedBoxHeight(10.h), - text14w400white('Upload banner image'), - sizedBoxHeight(8.h), - SizedBox( - width: 270.w, - child: text10w400_whiteCenter( - "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"), - ), - ], - ), - ), + return Stack(children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill)), + ), + SingleChildScrollView( + child: Column(children: [ + // sizedBoxHeight(30.h), + Stack( + clipBehavior: Clip.none, + children: [ + Container( + height: 100.h, + width: 100.w, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: Color(0xFF434A53), width: 0.5.w), ), + child: Center( + child: filePath.isNotEmpty + ? ClipOval( + child: SizedBox.fromSize( + size: Size.fromRadius(50.r), + child: filePath.isNotEmpty + ? Image.file( + filePath[0]!, + fit: BoxFit.cover, + width: double.infinity, + ) + : Image.asset( + 'assets/images/png/Ellipse 37.png', + fit: BoxFit.cover), + ), + ) + : ClipOval( + child: SizedBox.fromSize( + size: Size.fromRadius(50.r), + child: communityeditobj! + .data! + .communityData! + .communityProfilePhoto! + .isNotEmpty + ? Image.network( + communityeditobj! + .data! + .communityData! + .communityProfilePhoto!, + fit: BoxFit.cover, + errorBuilder: + (context, error, stackTrace) { + // Error handling when image fails to load + return Image.asset( + "assets/images/png/Ellipse 37.png", + fit: BoxFit.cover, + ); + }, + ) + : Image.asset( + 'assets/images/png/Ellipse 37.png', + fit: BoxFit.cover), + ), + )), ), - ), - sizedBoxHeight(16.w), - commonGlassUI( - width: double.infinity, - height: 60.h, - borderRadius: BorderRadius.circular( 10.r), - customWidget: Center( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 12.w), - child: Row(children: [ - Container( - height: 40.h, - width: 40.w, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.r)), + Positioned( + right: -10, + bottom: 0, + child: InkWell( + onTap: () { + ImageUploadBottomSheet().showModal( + context, + false, + (result) { + if (result != null && result.isNotEmpty) { + var file = File(result); + filePath.cast(); + filePath.add(file); + isImageAdded = true; + setState(() {}); + if (Platform.isAndroid) { + Get.back(); + } + } else { + filePath.clear(); + isImageAdded = false; + setState(() {}); + } + }, + ); + }, + child: Container( + height: 35.h, + width: 35.w, + decoration: BoxDecoration( + color: Color(0xFFD90B2E), + shape: BoxShape.circle, + border: Border.all( + color: Color(0xFFD90B2E), width: 0.5.w)), + child: Center( child: Image.asset( - "assets/images/png/img2.png", - fit: BoxFit.cover, + 'assets/images/png/cameraicon.png', + height: 14.h, + width: 15.w, ), ), - sizedBoxWidth(8.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - text14400white("group1.png"), - sizedBoxHeight(2.h), - text12w400_FCFCFC_blur("10 kb") - ], - ), - Spacer(), - Image.asset( - 'assets/images/png/cancelicon.png', - height: 20.h, - width: 20.w, - ) - ]), + ), + )) + ], + ), + sizedBoxHeight(25.h), + text16w400_white("Edit community profile picture"), + sizedBoxHeight(30.h), + Padding( + padding: EdgeInsets.symmetric(horizontal: 16.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + text16w400_FCFCFC("Community banner image"), + sizedBoxHeight(16.h), + DottedBorder( + strokeWidth: 1, + dashPattern: [7, 4], + borderType: BorderType.RRect, + radius: Radius.circular(14.r), + color: Color(0xFF434A53), + child: commonGlassUI( + borderwidth: 0, + width: double.infinity, + height: 150.h, + borderRadius: BorderRadius.circular(10.r), + customWidget: bannerPath.isNotEmpty && isbannerAdded + ? Stack( + children: [ + Image.file( + bannerPath[0]!, + fit: BoxFit.cover, + width: double.infinity, + ), + // Positioned( + // right: 5, + // bottom: 5, + // child: InkWell( + // onTap: () { + // setState(() { + // bannerPath.clear(); + // isbannerAdded = false; + // }); + // }, + // child: Container( + // width: 27, + // height: 27, + // decoration: ShapeDecoration( + // color: Color(0xFF7E7E7E), + // shape: RoundedRectangleBorder( + // borderRadius: + // BorderRadius.circular(5), + // ), + // ), + // child: Icon( + // Icons.delete_outline_outlined, + // color: Colors.white, + // ), + // ), + // ), + // ), + ], + ) + : GestureDetector( + onTap: () { + ImageUploadBottomSheet().showModal( + context, + false, + (result) { + if (result != null && + result.isNotEmpty) { + var file = File(result); + + // Check if the file size exceeds 10 MB + int fileSizeInBytes = + file.lengthSync(); + double fileSizeInMB = + fileSizeInBytes / (1024 * 1024); + + if (fileSizeInMB > 10) { + // Show toast message if the file size exceeds 10 MB + utils.showToast( + "The selected file is too large. Max file size is 10 MB."); + } else { + // Clear the existing image and add the new one + bannerPath.clear(); + bannerPath.add(file); + isbannerAdded = true; + setState(() {}); + } + } else { + // Handle case where no image is selected + bannerPath.clear(); + isbannerAdded = false; + setState(() {}); + } + if (Platform.isAndroid) { + Get.back(); + } + }, + ); + }, + child: Padding( + padding: + EdgeInsets.symmetric(vertical: 16.h), + child: Column( + children: [ + Image.asset( + "assets/images/png/cameraicon2.png", + height: 36.h, + width: 36.w, + ), + SizedBox(height: 10.h), + text14w400white( + 'Upload banner image'), + SizedBox(height: 8.h), + SizedBox( + width: 270.w, + child: text8w400_8A8A8A( + "Allowed file extensions: jpg, png, gif Max file size: 10 MB"), + ), + ], + ), + ), + ), ), ), - borderwidth: 1), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Community name"), - sizedBoxHeight(14.h), - CustomTextFormField( - textEditingController: communitynameController, - validator: (val) { - if (val == null || val.isEmpty) { - return 'Enter Community name'; - } - return null; - }, + sizedBoxHeight(16.w), + bannerPath.isNotEmpty && isbannerAdded + ? commonGlassUI( + width: double.infinity, + height: 60.h, + borderRadius: BorderRadius.circular(10.r), + customWidget: Center( + child: Padding( + padding: + EdgeInsets.symmetric(horizontal: 12.w), + child: Row( + children: [ + // Conditionally render image or placeholder + if (bannerPath.isNotEmpty && + isbannerAdded) + Container( + height: 40.h, + width: 40.w, + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(5.r), + ), + child: Image.file( + bannerPath[0]!, + fit: BoxFit.cover, + width: double.infinity, + ), + ) + else + Container( + height: 40.h, + width: 40.w, + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(5.r), + ), + child: Image.asset( + 'assets/images/png/img2.png', + fit: BoxFit.cover, + width: double.infinity, + ), + ), + SizedBox(width: 8.w), + Spacer(), + InkWell( + onTap: () { + setState(() { + // Clear the image and update the state + bannerPath.clear(); + isbannerAdded = false; + }); + // Optionally debug state values + print("bannerPath: $bannerPath"); + print( + "isbannerAdded: $isbannerAdded"); + }, + child: Image.asset( + 'assets/images/png/cancelicon.png', + height: 20.h, + width: 20.w, + ), + ), + ], + ), + ), + ), + borderwidth: 1, + ) + : SizedBox(), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Community name*"), + sizedBoxHeight(14.h), + CustomTextFormField( + textEditingController: communitynameController, + validator: (val) { + if (val == null || val.isEmpty) { + return 'Enter Community name'; + } + return null; + }, + hintText: 'Enter type of community', + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Group description"), + sizedBoxHeight(14.h), + CustomTextFormField( + // maxlines: 3, + hintText: 'Enter description', + textEditingController: descriptionController, + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Type of community*"), + sizedBoxHeight(14.h), + CustomDropDownRadio( + header: "", + title: "", + listData: _typeCommunityMap.keys.toList(), + onItemSelected: _onItemSelected, + leadingImage: SizedBox(), + initialSelectedValue: _selectedtypecommunity, + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Location*"), + sizedBoxHeight(14.h), + CustomTextFormField( + textEditingController: locationcontroller, + inputFormatters: [ + RemoveEmojiInputFormatter(), + // FilteringTextInputFormatter.allow(RegExp('[a-zA-Z ]')) + ], + hintText: 'Enter location', + validator: (val) { + if (val == null || val.isEmpty) { + return 'Enter location'; + } + return null; + }, + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Primary activity*"), + sizedBoxHeight(14.h), + CustomDropDownRadio( + showOtherOption: true, + header: "", + title: "", + listData: _activitydrop, + onItemSelected: getCatIdFromName, + leadingImage: SizedBox(), + initialSelectedValue: selectedActivityName.toString(), + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Website link"), + sizedBoxHeight(14.h), + CustomTextFormField( + textEditingController: websitelinkcontroller, + validator: (val) { + if (!isValidWebBannerLink(val)) { + return 'Please enter a valid web banner link.'; + } + return null; + }, + hintText: 'Enter website link', + ), + sizedBoxHeight(25.h), + sizedBoxHeight(50.h), + CustomButton(text: 'Save changes', onPressed: () {}), + sizedBoxHeight(50.h), + ], ), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Group description"), - sizedBoxHeight(14.h), - CustomTextFormField2( - maxlines: 3, - textEditingController: descriptionController, - ), - text16w400_FCFCFC("Type of community"), - sizedBoxHeight(14.h), - CustomDropDownRadio( - header: "", - title: "", - listData: ["Public", "Private - Request to join"], - onItemSelected: (p0) {}, - leadingImage: SizedBox()), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Location*"), - sizedBoxHeight(14.h), - CustomDropDownRadio( - header: "", - title: "", - listData: ["Public", "Private", "Secret"], - onItemSelected: (p0) {}, - leadingImage: SizedBox()), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Primary activity*"), - sizedBoxHeight(14.h), - CustomDropDownRadio( - showOtherOption: true, - header: "", - title: "", - listData: ["Sports", "Hobby"], - onItemSelected: (p0) {}, - leadingImage: SizedBox()), - sizedBoxHeight(50.h), - CustomButton(text: 'Save changes', onPressed: () {}), - sizedBoxHeight(50.h), - ], - ), + ) + ]), ) - ]), - ) - ])); + ]); + }, + )); } } diff --git a/lib/sidemenu/Community/Members/CommunityMembers.dart b/lib/sidemenu/Community/Members/CommunityMembers.dart index 55b3e61..8c952e8 100644 --- a/lib/sidemenu/Community/Members/CommunityMembers.dart +++ b/lib/sidemenu/Community/Members/CommunityMembers.dart @@ -200,18 +200,18 @@ class _CommunityMembersState extends State { CrossAxisAlignment.start, children: [ mainFollowersData.iamPrincipal! - .userName == + .fullName == null || mainFollowersData .iamPrincipal! - .userName! + .fullName! .isEmpty == true ? text16w400_FCFCFC("Regroup") : text16w400_FCFCFC( mainFollowersData .iamPrincipal! - .userName!), + .fullName!), sizedBoxHeight(4.h), mainFollowersData.iamPrincipal! .userName == diff --git a/lib/sidemenu/Community/MyCommunity/Model/communityMebersModel.dart b/lib/sidemenu/Community/MyCommunity/Model/communityMebersModel.dart index ceca38e..f4661d4 100644 --- a/lib/sidemenu/Community/MyCommunity/Model/communityMebersModel.dart +++ b/lib/sidemenu/Community/MyCommunity/Model/communityMebersModel.dart @@ -51,6 +51,7 @@ class IamPrincipal { required this.id, required this.principalTypeXid, required this.userName, + required this.fullName, required this.profilePhoto, required this.isUserPinned, }); @@ -58,6 +59,7 @@ class IamPrincipal { final int? id; final int? principalTypeXid; final String? userName; + final String? fullName; final String? profilePhoto; final bool? isUserPinned; @@ -66,6 +68,7 @@ class IamPrincipal { id: json["id"], principalTypeXid: json["principal_type_xid"], userName: json["user_name"], + fullName: json["full_name"], profilePhoto: json["profile_photo"], isUserPinned: json["is_user_pinned"], ); diff --git a/lib/sidemenu/Community/MyCommunity/Model/communityeditpageModel.dart b/lib/sidemenu/Community/MyCommunity/Model/communityeditpageModel.dart new file mode 100644 index 0000000..d8493e6 --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/Model/communityeditpageModel.dart @@ -0,0 +1,185 @@ +class CommunityinfopageEditModel { + CommunityinfopageEditModel({ + required this.status, + required this.statusCode, + required this.message, + required this.data, + }); + + final String? status; + final int? statusCode; + final String? message; + final Data? data; + + factory CommunityinfopageEditModel.fromJson(Map json){ + return CommunityinfopageEditModel( + status: json["status"], + statusCode: json["status_code"], + message: json["message"], + data: json["data"] == null ? null : Data.fromJson(json["data"]), + ); + } + +} + +class Data { + Data({ + required this.typesOfCommunity, + required this.communityData, + }); + + final List typesOfCommunity; + final CommunityData? communityData; + + factory Data.fromJson(Map json){ + return Data( + typesOfCommunity: json["typesOfCommunity"] == null ? [] : List.from(json["typesOfCommunity"]!.map((x) => TypesOfCommunity.fromJson(x))), + communityData: json["communityData"] == null ? null : CommunityData.fromJson(json["communityData"]), + ); + } + +} + +class CommunityData { + CommunityData({ + required this.id, + required this.communityProfilePhoto, + required this.communityBannerImage, + required this.communityName, + required this.communityLocation, + required this.communityDescription, + required this.communityTypeXid, + required this.activityXid, + required this.isActive, + required this.totalGroup, + required this.totalAnnouncements, + required this.activityData, + required this.communityTypeData, + }); + + final int? id; + final String? communityProfilePhoto; + final String? communityBannerImage; + final String? communityName; + final String? communityLocation; + final String? communityDescription; + final int? communityTypeXid; + final int? activityXid; + final int? isActive; + final int? totalGroup; + final int? totalAnnouncements; + final ActivityData? activityData; + final CommunityTypeData? communityTypeData; + + factory CommunityData.fromJson(Map json){ + return CommunityData( + id: json["id"], + communityProfilePhoto: json["community_profile_photo"], + communityBannerImage: json["community_banner_image"], + communityName: json["community_name"], + communityLocation: json["community_location"], + communityDescription: json["community_description"], + communityTypeXid: json["community_type_xid"], + activityXid: json["activity_xid"], + isActive: json["is_active"], + totalGroup: json["total_group"], + totalAnnouncements: json["total_announcements"], + activityData: json["activity_data"] == null ? null : ActivityData.fromJson(json["activity_data"]), + communityTypeData: json["community_type_data"] == null ? null : CommunityTypeData.fromJson(json["community_type_data"]), + ); + } + +} + +class ActivityData { + ActivityData({ + required this.id, + required this.title, + required this.description, + required this.image, + required this.deletedAt, + required this.createdAt, + required this.updatedAt, + }); + + final int? id; + final String? title; + final String? description; + final String? image; + final dynamic deletedAt; + final DateTime? createdAt; + final DateTime? updatedAt; + + factory ActivityData.fromJson(Map json){ + return ActivityData( + id: json["id"], + title: json["title"], + description: json["description"], + image: json["image"], + deletedAt: json["deleted_at"], + createdAt: DateTime.tryParse(json["created_at"] ?? ""), + updatedAt: DateTime.tryParse(json["updated_at"] ?? ""), + ); + } + +} + +class CommunityTypeData { + CommunityTypeData({ + required this.id, + required this.name, + required this.image, + required this.description, + required this.isActive, + required this.createdBy, + required this.modifiedBy, + required this.deletedAt, + required this.createdAt, + required this.updatedAt, + }); + + final int? id; + final String? name; + final dynamic image; + final dynamic description; + final int? isActive; + final dynamic createdBy; + final dynamic modifiedBy; + final dynamic deletedAt; + final dynamic createdAt; + final dynamic updatedAt; + + factory CommunityTypeData.fromJson(Map json){ + return CommunityTypeData( + id: json["id"], + name: json["name"], + image: json["image"], + description: json["description"], + isActive: json["is_active"], + createdBy: json["created_by"], + modifiedBy: json["modified_by"], + deletedAt: json["deleted_at"], + createdAt: json["created_at"], + updatedAt: json["updated_at"], + ); + } + +} + +class TypesOfCommunity { + TypesOfCommunity({ + required this.id, + required this.name, + }); + + final int? id; + final String? name; + + factory TypesOfCommunity.fromJson(Map json){ + return TypesOfCommunity( + id: json["id"], + name: json["name"], + ); + } + +} diff --git a/lib/sidemenu/Community/MyCommunity/NewCommunity.dart b/lib/sidemenu/Community/MyCommunity/NewCommunity.dart index bd23833..7c39a31 100644 --- a/lib/sidemenu/Community/MyCommunity/NewCommunity.dart +++ b/lib/sidemenu/Community/MyCommunity/NewCommunity.dart @@ -196,8 +196,8 @@ class _NewCommunityState extends State { } } else { // Handle case where no image is selected - bannerPath.clear(); - isbannerAdded = false; + filePath.clear(); + isImageAdded = false; setState(() {}); } }, diff --git a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart index 4cfcb1e..56e75d4 100644 --- a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart +++ b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart @@ -138,7 +138,9 @@ class _CommunityDetailsState extends State { PopupMenuDivider(), PopupMenuItem( onTap: () { - Get.toNamed(RouteName.communitysetting); + Get.toNamed(RouteName.communitysetting,arguments: { + 'communityid' : CommunityId, + }); }, child: Padding( padding: EdgeInsets.symmetric(horizontal: 8.w), diff --git a/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart b/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart index e874d09..d093096 100644 --- a/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart +++ b/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart @@ -6,11 +6,13 @@ import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/Model/communityMebersModel.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/Model/communityeditpageModel.dart'; import 'package:regroup/sidemenu/Community/MyCommunity/Model/communitygroupsModel.dart'; CommunityAddgroupsModel? communityaddgroupobj; CommunitygroupsModel? communitygroupspobj; CommunityMembersModel? communitymembersobj; +CommunityinfopageEditModel? communityeditobj; @@ -59,4 +61,16 @@ class Getcommunity { return response; } + Future> getCommunityeditpage(updata) async { + final response = await NetworkApiServices().getApi( + "${ApiUrls.geteditcommunity}?community_id=$updata", + // optionalpar: false + ); + if (response.status == ResponseStatus.SUCCESS) { + communityeditobj = CommunityinfopageEditModel.fromJson(response.data); + log(communityeditobj!.data.toString()); + } + return response; + } + } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 393a293..a10304a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1214,9 +1214,7 @@ packages: source: hosted version: "7.0.0" sqflite: - - dependency: transitive - + dependency: "direct main" description: name: sqflite sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d From d365d739316769c1a4a91a2c1c01aa9e96175d37 Mon Sep 17 00:00:00 2001 From: kishan Date: Fri, 16 Aug 2024 11:40:12 +0530 Subject: [PATCH 2/2] normal card and feed completee --- lib/Login/View/loginscreen.dart | 2 + lib/Login/ViewModel/LoginApi.dart | 3 + .../Community/ViewModel/getmethod.dart | 10 +- .../Community_HomePage/Community.dart | 412 ++++++++++-------- .../view_model/CountersHelper.dart | 15 +- lib/onboarding/SplashScreen.dart | 2 + 6 files changed, 254 insertions(+), 190 deletions(-) diff --git a/lib/Login/View/loginscreen.dart b/lib/Login/View/loginscreen.dart index 0d187e4..e9a2c36 100644 --- a/lib/Login/View/loginscreen.dart +++ b/lib/Login/View/loginscreen.dart @@ -7,6 +7,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Login/ViewModel/LoginApi.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Utils/Common/AppleOAuthService.dart'; import 'package:regroup/Utils/Common/CustomNextButton.dart'; import 'package:regroup/Utils/Common/CustomTextformfield.dart'; @@ -70,6 +71,7 @@ class _LoginScreenState extends State { snackPosition: SnackPosition.BOTTOM, ); // Get.toNamed(RouteName.mainscreen,arguments: 0); + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = diff --git a/lib/Login/ViewModel/LoginApi.dart b/lib/Login/ViewModel/LoginApi.dart index 80cf01b..7d0929c 100644 --- a/lib/Login/ViewModel/LoginApi.dart +++ b/lib/Login/ViewModel/LoginApi.dart @@ -4,6 +4,7 @@ import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; import 'package:regroup/Global.dart'; import 'package:regroup/Login/Model/LoginModel.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/onboarding/Signup/view_model/getUserprofile.dart'; import 'package:regroup/resources/routes/route_name.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -105,6 +106,7 @@ class LoginAPI { return ResponseData( "go-to-signin-via-oauth", ResponseStatus.SUCCESS); } else { + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = @@ -143,6 +145,7 @@ class LoginAPI { "go-to-signin-via-oauth", ResponseStatus.SUCCESS); } else { // Get.toNamed(RouteName.mainscreen); + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = diff --git a/lib/Main_Screens/Community/ViewModel/getmethod.dart b/lib/Main_Screens/Community/ViewModel/getmethod.dart index 5733b1c..2a72663 100644 --- a/lib/Main_Screens/Community/ViewModel/getmethod.dart +++ b/lib/Main_Screens/Community/ViewModel/getmethod.dart @@ -5,20 +5,18 @@ import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; -// FetchlikeIconsModel? likeiconsobj; +FetchlikeIconsModel? fetchlikeIconsModel; class Communityallgetmethod { - - Future> getLikeicons() async { + Future> getLikeicons() async { final response = await NetworkApiServices().getApi( ApiUrls.getLikeicons, // optionalpar: false ); if (response.status == ResponseStatus.SUCCESS) { - // likeiconsobj = FetchlikeIconsModel.fromJson(response.data); + fetchlikeIconsModel = FetchlikeIconsModel.fromJson(response.data); // log(likeiconsobj!.data.toString()); } return response; } - -} \ No newline at end of file +} diff --git a/lib/Main_Screens/Community_HomePage/Community.dart b/lib/Main_Screens/Community_HomePage/Community.dart index 955fea9..f550bbd 100644 --- a/lib/Main_Screens/Community_HomePage/Community.dart +++ b/lib/Main_Screens/Community_HomePage/Community.dart @@ -30,6 +30,7 @@ import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Main_Screens/Community/ViewModel/postmethod.dart'; import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart'; import 'package:regroup/Main_Screens/Community_HomePage/view_model/communitypostmethod.dart'; +import 'package:regroup/Utils/Common/ShimmerCommon.dart'; // import 'package:regroup/Feed%20Module/sidemenu/sidemenu.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; import 'package:regroup/Utils/dialogs.dart'; @@ -217,39 +218,29 @@ class _FeedTabState extends State { super.initState(); } - Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _fetchIcons() { + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in commonobjmodel!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } - bool _isDataInitialized = true; - - Future setValues() async { - if (_isDataInitialized) { + setValues() { + if (mounted) { combinedList.clear(); combinedListGlobal.clear(); combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost); @@ -258,10 +249,7 @@ class _FeedTabState extends State { combinedListGlobal.addAll(combinedList); _setModel(); countersHelper.setListsPopular(); - - await _fetchIcons(); - - _isDataInitialized = false; + _fetchIcons(); } } @@ -335,92 +323,184 @@ class _FeedTabState extends State { @override Widget build(BuildContext context) { - return FutureBuilder( - future: feedfuture, - builder: (ctx, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); - } + return Obx( + () => countersHelper.updateFeedsPage.value + ? FutureBuilder( + future: FeedpostApi().getFeedPostApi(), + builder: (ctx, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: ShimmerCommon()); + } - if (snapshot.hasError) { - return Center( - child: Text( - '${snapshot.error} occurred', - style: TextStyle(fontSize: 18.spMin), - ), - ); - } + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - setValues(); - return Stack( - clipBehavior: Clip.none, - children: [ - Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/png/Ellipse 1496.png"), - fit: BoxFit.fill), - ), - ), - combinedList.isEmpty - ? Center( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "No posts are currently pinned", - style: TextStyle( - color: Colors.white, - fontSize: 16.sp, - fontWeight: FontWeight.w600), - ) - ], - ), - ) - : Column( - children: [ - sizedBoxHeight(20.h), - Expanded( - child: ListView.builder( - shrinkWrap: true, - itemCount: commonobjmodel!.data.length, - itemBuilder: (context, index) { - var timeAgo = ConvertServerDateToUserDate() - .convertServerDateToReadableFormate( - commonobjmodel!.data[index].createdAt - .toString()); - - return Column( - children: [ - NormalCardTile( - tags: _sortTags(index), - create_at: timeAgo ?? '1 hour', - commonObj: commonobjmodel!.data[index], - forWhichTab: 'feed', - reactions: _reactions, - selectedReactions: _selectedReactions, - currentIndex: index, - ), - sizedBoxHeight(20.h) - ], - ); - }, - ), + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + log("TRUE"); + setValues(); + return Stack( + clipBehavior: Clip.none, + children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + "assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill), ), - ], - ) - ], - ); - } - return Container(); - }, + ), + combinedList.isEmpty + ? Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "No posts are currently pinned", + style: TextStyle( + color: Colors.white, + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ) + ], + ), + ) + : Column( + children: [ + sizedBoxHeight(20.h), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: commonobjmodel!.data.length, + itemBuilder: (context, index) { + var timeAgo = ConvertServerDateToUserDate() + .convertServerDateToReadableFormate( + commonobjmodel! + .data[index].createdAt + .toString()); + + return Column( + children: [ + NormalCardTile( + tags: _sortTags(index), + create_at: timeAgo ?? '1 hour', + commonObj: + commonobjmodel!.data[index], + forWhichTab: 'feed', + reactions: _reactions, + selectedReactions: + _selectedReactions, + currentIndex: index, + ), + sizedBoxHeight(20.h) + ], + ); + }, + ), + ), + ], + ) + ], + ); + } + return Container(); + }, + ) + : FutureBuilder( + future: FeedpostApi().getFeedPostApi(), + builder: (ctx, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: ShimmerCommon()); + } + + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + log("FALSE"); + setValues(); + return Stack( + clipBehavior: Clip.none, + children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + "assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill), + ), + ), + combinedList.isEmpty + ? Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "No posts are currently pinned", + style: TextStyle( + color: Colors.white, + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ) + ], + ), + ) + : Column( + children: [ + sizedBoxHeight(20.h), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: commonobjmodel!.data.length, + itemBuilder: (context, index) { + var timeAgo = ConvertServerDateToUserDate() + .convertServerDateToReadableFormate( + commonobjmodel! + .data[index].createdAt + .toString()); + + return Column( + children: [ + NormalCardTile( + tags: _sortTags(index), + create_at: timeAgo ?? '1 hour', + commonObj: + commonobjmodel!.data[index], + forWhichTab: 'feed', + reactions: _reactions, + selectedReactions: + _selectedReactions, + currentIndex: index, + ), + sizedBoxHeight(20.h) + ], + ); + }, + ), + ), + ], + ) + ], + ); + } + return Container(); + }, + ), ); } } @@ -560,6 +640,8 @@ class _NormalCardTileState extends State { if (data.status == ResponseStatus.SUCCESS) { countersHelper.pinButtonPopular[widget.currentIndex] = !countersHelper.pinButtonPopular[widget.currentIndex]; + countersHelper.updateFeedsPage.value = + !countersHelper.updateFeedsPage.value; return utils.showToast(data.message); } else { return utils.showToast(data.message); @@ -573,6 +655,10 @@ class _NormalCardTileState extends State { @override Widget build(BuildContext context) { + var imgUrl = widget.commonObj.image! + .split( + "https://regroup.betadelivery.com/storage/app/public/uploads/post_image/") + .last; return commonGlassUI( width: double.infinity, height: 765.h, @@ -751,14 +837,16 @@ class _NormalCardTileState extends State { 'currentIndex': widget.currentIndex }); if (result) { - setState(() {}); + setState(() { + + }); } }, - child: Container( + child: SizedBox( height: 360, width: double.infinity, child: CachedNetworkImage( - // cacheKey: "1st", + cacheKey: imgUrl, imageUrl: widget.commonObj.image!, fit: BoxFit.cover, placeholder: (context, url) => const Center( @@ -1081,31 +1169,23 @@ class _PopularTabState extends State { } Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in popularpostobj!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } @@ -1195,11 +1275,7 @@ class _PopularTabState extends State { future: popularfuture, builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); + return const Center(child: ShimmerCommon()); } if (snapshot.hasError) { @@ -1301,32 +1377,24 @@ class _LatestTabState extends State { final CountersHelper countersHelper = Get.find(); int? likeIconIdnew; - Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _fetchIcons() { + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in latestpostobj!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } @@ -1336,7 +1404,7 @@ class _LatestTabState extends State { if (_isDataInitialized) { _setModel(); countersHelper.setListsPopular(); - await _fetchIcons(); + _fetchIcons(); _isDataInitialized = false; } @@ -1416,13 +1484,7 @@ class _LatestTabState extends State { future: futureGroup.future, builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return - // ShimmerCommon(); - const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); + return const Center(child: ShimmerCommon()); } if (snapshot.hasError) { diff --git a/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart index a142fcb..f2ff703 100644 --- a/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart +++ b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart @@ -4,20 +4,21 @@ import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart'; import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart'; List combinedListGlobal = []; - CommonDatumObjModel? commonobjmodel; +CommonDatumObjModel? commonobjmodel; + class CountersHelper extends GetxController { RxList likesCounterPopular = [].obs; RxList commentsCounterPopular = [].obs; RxList savePostCounterPopular = [].obs; RxList saveButtonPopular = [].obs; - RxList pinButtonPopular = [].obs; - - setListsPopular() { +List pinButtonPopular = []; + RxBool updateFeedsPage = false.obs; + setListsPopular() { likesCounterPopular.clear(); commentsCounterPopular.clear(); savePostCounterPopular.clear(); saveButtonPopular.clear(); - + pinButtonPopular.clear(); for (var i = 0; i < commonobjmodel!.data.length; i++) { likesCounterPopular.add(commonobjmodel?.data[i].likecount ?? 0); commentsCounterPopular @@ -52,8 +53,4 @@ class CountersHelper extends GetxController { savePostCounterFeed.add(latestpostobj!.data[i].totalSave ?? 0); } } - - - - } diff --git a/lib/onboarding/SplashScreen.dart b/lib/onboarding/SplashScreen.dart index 27aada9..8918a68 100644 --- a/lib/onboarding/SplashScreen.dart +++ b/lib/onboarding/SplashScreen.dart @@ -11,6 +11,7 @@ import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Global.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Main_Screens/ProfileTab/EditProfile/ViewModel/InterestApiList.dart'; import 'package:regroup/Utils/Common/NoInternet.dart'; import 'package:regroup/Utils/dialogs.dart'; @@ -46,6 +47,7 @@ class _SplashScreenState extends State { if (token == null || token!.isEmpty) { Get.toNamed(RouteName.onboarding1); } else { + await Communityallgetmethod().getLikeicons(); await InterestListApi().getinterestlistApi(); await Uploadata(deviceName); await Getuserdetails().Getuser().then((value) {