diff --git a/assets/images/png/PinnedIcon.png b/assets/images/png/PinnedIcon.png new file mode 100644 index 0000000..8813bc3 Binary files /dev/null and b/assets/images/png/PinnedIcon.png differ diff --git a/lib/Common/api_urls.dart b/lib/Common/api_urls.dart index 3abf24d..61cb339 100644 --- a/lib/Common/api_urls.dart +++ b/lib/Common/api_urls.dart @@ -159,4 +159,12 @@ class ApiUrls { static const getpostdetail = "${baseUrl}fetch-single-post"; static const getpopularTagsdetails = "${baseUrl}fetch-popular-post"; + + static const postcreatecommunity = "${baseUrl}create-community"; + + static const getcommunityaddgroups = "${baseUrl}fetch-groups-to-add"; + + static const getcommunitygroups = "${baseUrl}fetch-community-all-groups"; + + } diff --git a/lib/Main_Screens/Community/Model/CommonDatumObjModel.dart b/lib/Main_Screens/Community/Model/CommonDatumObjModel.dart new file mode 100644 index 0000000..98fb595 --- /dev/null +++ b/lib/Main_Screens/Community/Model/CommonDatumObjModel.dart @@ -0,0 +1,251 @@ +class CommonDatumObjModel { + CommonDatumObjModel({ + required this.status, + required this.statusCode, + required this.message, + required this.data, + }); + + final String? status; + final int? statusCode; + final String? message; + final List data; + + factory CommonDatumObjModel.fromJson(Map json) { + return CommonDatumObjModel( + status: json["status"], + statusCode: json["status_code"], + message: json["message"], + data: json["data"] == null + ? [] + : List.from( + json["data"]!.map((x) => CommonDatumObjModelData.fromJson(x))), + ); + } +} + +class CommonDatumObjModelData { + CommonDatumObjModelData({ + required this.id, + required this.likecount, + required this.isISaved, + required this.tagsXid, + required this.isILiked, + required this.totalComment, + required this.totalSave, + required this.iamPrincipalXid, + required this.postIn, + required this.caption, + required this.image, + required this.manageTagsXids, + required this.postAs, + required this.ctaTitle, + required this.ctaLink, + required this.createdAt, + required this.likeIcon, + required this.totalViewCount, + required this.totalReactionCount, + required this.totalCommentCount, + required this.totalImpressionCount, + required this.totalPopularScore, + required this.totalHoursAgo, + required this.iamPrincipal, + required this.community, + required this.attachTags, + }); + + final int? id; + final int? likecount; + final bool? isISaved; + final List tagsXid; + final bool? isILiked; + final int? totalComment; + final int? totalSave; + final int? iamPrincipalXid; + final int? postIn; + final String? caption; + final String? image; + final String? manageTagsXids; + final String? postAs; + final String? ctaTitle; + final String? ctaLink; + final DateTime? createdAt; + final LikeIcon1? likeIcon; + final int? totalViewCount; + final int? totalReactionCount; + final int? totalCommentCount; + final int? totalImpressionCount; + final int? totalPopularScore; + final int? totalHoursAgo; + final IamPrincipal? iamPrincipal; + final Community? community; + final List attachTags; + + factory CommonDatumObjModelData.fromJson(Map json) { + return CommonDatumObjModelData( + id: json["id"], + likecount: json["likecount"], + isISaved: json["is_i_saved"], + tagsXid: json["tags_xid"] == null + ? [] + : List.from(json["tags_xid"]!.map((x) => x)), + isILiked: json["is_i_liked"], + totalComment: json["total_comment"], + totalSave: json["total_save"], + iamPrincipalXid: json["iam_principal_xid"], + postIn: json["post_in"], + caption: json["caption"], + image: json["image"], + manageTagsXids: json["manage_tags_xids"], + postAs: json["post_as"], + ctaTitle: json["cta_title"], + ctaLink: json["cta_link"], + createdAt: DateTime.tryParse(json["created_at"] ?? ""), + likeIcon: + json["likeIcon"] == null ? null : LikeIcon1.fromJson(json["likeIcon"]), + totalViewCount: json["totalViewCount"], + totalReactionCount: json["totalReactionCount"], + totalCommentCount: json["totalCommentCount"], + totalImpressionCount: json["totalImpressionCount"], + totalPopularScore: json["totalPopularScore"], + totalHoursAgo: json["totalHoursAgo"], + iamPrincipal: json["iam_principal"] == null + ? null + : IamPrincipal.fromJson(json["iam_principal"]), + community: json["community"] == null + ? null + : Community.fromJson(json["community"]), + attachTags: json["attach_tags"] == null + ? [] + : List.from( + json["attach_tags"]!.map((x) => AttachTag1.fromJson(x))), + ); + } +} + +class AttachTag1 { + AttachTag1({ + required this.managePostXid, + required this.manageTagXid, + required this.manageTag, + }); + + final int? managePostXid; + final int? manageTagXid; + final ManageTagPopular? manageTag; + + factory AttachTag1.fromJson(Map json) { + return AttachTag1( + managePostXid: json["manage_post_xid"], + manageTagXid: json["manage_tag_xid"], + manageTag: json["manage_tag"] == null + ? null + : ManageTagPopular.fromJson(json["manage_tag"]), + ); + } +} + +class ManageTagPopular { + ManageTagPopular({ + required this.id, + required this.isPinned, + required this.name, + }); + + final int? id; + final bool? isPinned; + final String? name; + + factory ManageTagPopular.fromJson(Map json) { + return ManageTagPopular( + id: json["id"], + isPinned: json["is_pinned"], + name: json["name"], + ); + } +} + +class Community { + Community({ + required this.id, + required this.communityProfilePhoto, + required this.communityName, + }); + + final int? id; + final String? communityProfilePhoto; + final String? communityName; + + factory Community.fromJson(Map json) { + return Community( + id: json["id"], + communityProfilePhoto: json["community_profile_photo"], + communityName: json["community_name"], + ); + } +} + +class IamPrincipal { + IamPrincipal({ + required this.id, + required this.isUserPinned, + required this.principalTypeXid, + required this.userName, + required this.fullName, + required this.profilePhoto, + }); + + final int? id; + final bool? isUserPinned; + final int? principalTypeXid; + final String? userName; + final String? fullName; + final String? profilePhoto; + + factory IamPrincipal.fromJson(Map json) { + return IamPrincipal( + id: json["id"], + isUserPinned: json["is_user_pinned"], + principalTypeXid: json["principal_type_xid"], + userName: json["user_name"], + fullName: json["full_name"], + profilePhoto: json["profile_photo"], + ); + } +} + +class LikeIcon1 { + LikeIcon1({ + required this.likeIconsXid, + required this.likeIcon, + }); + + final int? likeIconsXid; + final LikeIconClass1? likeIcon; + + factory LikeIcon1.fromJson(Map json) { + return LikeIcon1( + likeIconsXid: json["like_icons_xid"], + likeIcon: json["like_icon"] == null + ? null + : LikeIconClass1.fromJson(json["like_icon"]), + ); + } +} + +class LikeIconClass1 { + LikeIconClass1({ + required this.id, + required this.image, + }); + + final int? id; + final String? image; + + factory LikeIconClass1.fromJson(Map json) { + return LikeIconClass1( + id: json["id"], + image: json["image"], + ); + } +} diff --git a/lib/Main_Screens/MyCommunity/Model/FeedPostModel.dart b/lib/Main_Screens/Community/Model/FeedPostModel.dart similarity index 99% rename from lib/Main_Screens/MyCommunity/Model/FeedPostModel.dart rename to lib/Main_Screens/Community/Model/FeedPostModel.dart index dbe4abd..f3daee5 100644 --- a/lib/Main_Screens/MyCommunity/Model/FeedPostModel.dart +++ b/lib/Main_Screens/Community/Model/FeedPostModel.dart @@ -1,4 +1,4 @@ -class FeedPostModel { +class FeedPostModel { FeedPostModel({ required this.status, required this.statusCode, diff --git a/lib/Main_Screens/MyCommunity/Model/LatestPostModel.dart b/lib/Main_Screens/Community/Model/LatestPostModel.dart similarity index 99% rename from lib/Main_Screens/MyCommunity/Model/LatestPostModel.dart rename to lib/Main_Screens/Community/Model/LatestPostModel.dart index 5fe3cb6..0d8546a 100644 --- a/lib/Main_Screens/MyCommunity/Model/LatestPostModel.dart +++ b/lib/Main_Screens/Community/Model/LatestPostModel.dart @@ -11,7 +11,7 @@ class LatestpostModel { final String? message; final List data; - factory LatestpostModel.fromJson(Map json){ + factory LatestpostModel.fromJson(Map json){ return LatestpostModel( status: json["status"], statusCode: json["status_code"], diff --git a/lib/Main_Screens/MyCommunity/Model/PopularPostModel.dart b/lib/Main_Screens/Community/Model/PopularPostModel.dart similarity index 100% rename from lib/Main_Screens/MyCommunity/Model/PopularPostModel.dart rename to lib/Main_Screens/Community/Model/PopularPostModel.dart diff --git a/lib/Main_Screens/Community/Model/fetchicons.dart b/lib/Main_Screens/Community/Model/fetchicons.dart new file mode 100644 index 0000000..85d88a7 --- /dev/null +++ b/lib/Main_Screens/Community/Model/fetchicons.dart @@ -0,0 +1,64 @@ +class FetchlikeIconsModel { + String? status; + int? statusCode; + String? message; + List? data; + + FetchlikeIconsModel({this.status, this.statusCode, this.message, this.data}); + + FetchlikeIconsModel.fromJson(Map json) { + status = json['status']; + statusCode = json['status_code']; + message = json['message']; + if (json['data'] != null) { + data = []; + json['data'].forEach((v) { + data!.add(ReactionData.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = {}; + data['status'] = status; + data['status_code'] = statusCode; + data['message'] = message; + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class ReactionData { + int? id; + String image = ""; + + ReactionData({this.id, required this.image}); + + ReactionData.fromJson(Map json) { + id = json['id']; + image = json['image']; + } + + Map toJson() { + final Map data = {}; + data['id'] = id; + data['image'] = image; + return data; + } +} + +// class ReactionData { +// final int id; +// final String image; + +// ReactionData({required this.id, required this.image}); + +// factory ReactionData.fromJson(Map json) { +// return ReactionData( +// id: json['id'], +// image: json['image'], +// ); +// } +// } diff --git a/lib/Main_Screens/MyCommunity/View/CommunityDetail.dart b/lib/Main_Screens/Community/View/CommunityDetail.dart similarity index 100% rename from lib/Main_Screens/MyCommunity/View/CommunityDetail.dart rename to lib/Main_Screens/Community/View/CommunityDetail.dart diff --git a/lib/Main_Screens/MyCommunity/ViewModel/FeedPost.dart b/lib/Main_Screens/Community/ViewModel/FeedPost.dart similarity index 92% rename from lib/Main_Screens/MyCommunity/ViewModel/FeedPost.dart rename to lib/Main_Screens/Community/ViewModel/FeedPost.dart index 4ea916d..6bfe4ee 100644 --- a/lib/Main_Screens/MyCommunity/ViewModel/FeedPost.dart +++ b/lib/Main_Screens/Community/ViewModel/FeedPost.dart @@ -3,7 +3,7 @@ import 'package:regroup/Common/api_urls.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/FeedPostModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart'; FeedPostModel? feedpostobj; diff --git a/lib/Main_Screens/MyCommunity/ViewModel/LatestPost.dart b/lib/Main_Screens/Community/ViewModel/LatestPost.dart similarity index 91% rename from lib/Main_Screens/MyCommunity/ViewModel/LatestPost.dart rename to lib/Main_Screens/Community/ViewModel/LatestPost.dart index a1a277e..f536630 100644 --- a/lib/Main_Screens/MyCommunity/ViewModel/LatestPost.dart +++ b/lib/Main_Screens/Community/ViewModel/LatestPost.dart @@ -1,7 +1,7 @@ import 'package:regroup/Common/api_urls.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/LatestPostModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/LatestPostModel.dart'; LatestpostModel? latestpostobj; diff --git a/lib/Main_Screens/MyCommunity/ViewModel/PopularPost.dart b/lib/Main_Screens/Community/ViewModel/PopularPost.dart similarity index 88% rename from lib/Main_Screens/MyCommunity/ViewModel/PopularPost.dart rename to lib/Main_Screens/Community/ViewModel/PopularPost.dart index dc3debe..71d5e9b 100644 --- a/lib/Main_Screens/MyCommunity/ViewModel/PopularPost.dart +++ b/lib/Main_Screens/Community/ViewModel/PopularPost.dart @@ -1,11 +1,11 @@ import 'package:regroup/Common/api_urls.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/PopularPostModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/PopularPostModel.dart'; PopularpostModel? popularpostobj; -class PopularpostApi { +class PopularpostApi{ PopularpostApi(); Future> getPopularPostApi() async { diff --git a/lib/Main_Screens/MyCommunity/ViewModel/getmethod.dart b/lib/Main_Screens/Community/ViewModel/getmethod.dart similarity index 89% rename from lib/Main_Screens/MyCommunity/ViewModel/getmethod.dart rename to lib/Main_Screens/Community/ViewModel/getmethod.dart index a15c260..5733b1c 100644 --- a/lib/Main_Screens/MyCommunity/ViewModel/getmethod.dart +++ b/lib/Main_Screens/Community/ViewModel/getmethod.dart @@ -3,7 +3,7 @@ import 'dart:developer'; import 'package:regroup/Common/api_urls.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/fetchicons.dart'; +import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; // FetchlikeIconsModel? likeiconsobj; diff --git a/lib/Main_Screens/MyCommunity/ViewModel/postmethod.dart b/lib/Main_Screens/Community/ViewModel/postmethod.dart similarity index 100% rename from lib/Main_Screens/MyCommunity/ViewModel/postmethod.dart rename to lib/Main_Screens/Community/ViewModel/postmethod.dart diff --git a/lib/Main_Screens/Community_HomePage/Community.dart b/lib/Main_Screens/Community_HomePage/Community.dart index d9924a8..955fea9 100644 --- a/lib/Main_Screens/Community_HomePage/Community.dart +++ b/lib/Main_Screens/Community_HomePage/Community.dart @@ -2,11 +2,13 @@ import 'dart:developer'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_reaction_button/flutter_reaction_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:get/get_state_manager/get_state_manager.dart'; import 'package:regroup/Common/CommonBottomNavigationBar.dart'; import 'package:regroup/Common/CommonGlassmorphism.dart'; import 'package:regroup/Common/CommonTabBar.dart'; @@ -15,14 +17,17 @@ import 'package:regroup/Common/ConvertServerDateToUserDate.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/MainScreen.dart'; import 'package:regroup/Feed%20Module/Main_Screens/Community/view_model/getApi.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/FeedPostModel.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/PopularPostModel.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/fetchicons.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/FeedPost.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/LatestPost.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/PopularPost.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/getmethod.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/postmethod.dart'; +import 'package:regroup/Main_Screens/Community/Model/CommonDatumObjModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart' + as feedobj; +// import 'package:regroup/Main_Screens/Community/Model/PopularPostModel.dart'; +// import 'package:regroup/Main_Screens/Community/Model/LatestPostModel.dart' as latest; +import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/FeedPost.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/PopularPost.dart'; +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/Feed%20Module/sidemenu/sidemenu.dart'; @@ -34,6 +39,8 @@ import 'package:regroup/sidemenu/sidemenu.dart'; import 'package:async/src/future_group.dart'; import 'package:regroup/sidemenu/view_model/postmethod.dart'; +import 'view_model/CountersHelper.dart'; + class CommunityScreen extends StatefulWidget { const CommunityScreen({super.key}); @@ -43,7 +50,7 @@ class CommunityScreen extends StatefulWidget { class _CommunityScreenState extends State { final GlobalKey _scaffoldKey1 = GlobalKey(); - + final CountersHelper countersHelper = Get.put(CountersHelper()); @override Widget build(BuildContext context) { return Scaffold( @@ -198,70 +205,18 @@ class FeedTab extends StatefulWidget { class _FeedTabState extends State { late Future feedfuture; - + List _reactions = []; + Map _selectedReactions = {}; + final CountersHelper countersHelper = Get.find(); + int? likeIconIdnew; + List combinedList = []; @override void initState() { feedfuture = FeedpostApi().getFeedPostApi(); - // .then((value) { - // _initializeData(); - // }); + super.initState(); } - List combinedList = []; - - // setValues() { - // combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost); - // combinedList.addAll(feedpostobj!.data!.pinnedUserPost); - // combinedList.addAll(feedpostobj!.data!.pinnedTagsPost); - // // _initializeData(); - - // // for (var i = 0; i < feedpostobj!.data!.pinnedCommunityPost.length; i++) { - - // // } - // // for (var j = 0; j < feedpostobj!.data!.pinnedUserPost.length; j++) { - // // } - // // for (var k = 0; k < feedpostobj!.data!.pinnedTagsPost.length; k++) { - // // } - // } - - bool _isDataInitialized = false; - - Future setValues() async { - if (_isDataInitialized) return; // Check if data is already initialized - - try { - combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost); - combinedList.addAll(feedpostobj!.data!.pinnedUserPost); - combinedList.addAll(feedpostobj!.data!.pinnedTagsPost); - - await _initializeData(); - - setState(() { - _isDataInitialized = true; - }); - } catch (e) { - // Handle any errors that occur during the fetch - print('Error fetching data: $e'); - } - } - - List _reactions = []; - Map _selectedReactions = {}; - - Future _initializeData() async { - await _fetchIcons(); - // _initializeSelectedReaction(); - for (var post in combinedList) { - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; // This is safe now - } else { - likeIconIdnew = 0; // Or handle it as needed - } - _initializeSelectedReaction(post.id!); // Pass the post ID - } - } - Future _fetchIcons() async { var response = await Communityallgetmethod().getLikeicons(); if (response.status == ResponseStatus.SUCCESS) { @@ -269,128 +224,113 @@ class _FeedTabState extends State { FetchlikeIconsModel fetchlikeIconsModel = FetchlikeIconsModel.fromJson(responseData); - setState(() { - _reactions = fetchlikeIconsModel.data - ?.map((data) => ReactionData( - id: data.id!, - image: data.image!, - )) - .toList() ?? - []; - for (var post in combinedList) { - _initializeSelectedReaction(post.id!); + _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, + ); + + _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'); } - }); - } - } - - int? likeIconIdnew; - - void _initializeSelectedReaction(int postId) { - // Check if there's a stored likeIconId for this post - if (likeIconIdnew != null && likeIconIdnew != 0 && _reactions.isNotEmpty) { - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - setState(() { - _selectedReactions[postId] = - selectedReaction; // Set selected reaction for this post - print( - 'Selected reaction for post $postId is ${_selectedReactions[postId].toString()}'); - log(_selectedReactions[postId].toString()); - }); - } else { - setState(() { - _selectedReactions[postId] = null; // No reaction selected - print('No reaction selected for post $postId'); - }); - } - } - - Future _handleReactionChange(ReactionData? reaction, int postId) async { - // Check if the postId is valid - if (postId == null) return; - - setState(() { - if (reaction == null) { - _selectedReactions[postId] = - null; // Mark reaction as removed for this post - } else { - _selectedReactions[postId] = - reaction; // Set the selected reaction for this post } - }); - - try { - await LikeUploaddata( - reaction?.id, - postId, - ); - } catch (error) { - print('Error updating reaction: $error'); - setState(() { - _selectedReactions[postId] = - reaction; // Restore previous reaction if needed - }); + setState(() {}); } } - LikeUploaddata(int? likeIconId, int? postid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": postid, - "like_icons_xid": likeIconId ?? '', - }; - final data = await CommunitypostMethod().postLikepost(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - print("like done"); - return utils.showToast(data.message); - } else { - // Get.back(); - print("like not done"); - return utils.showToast(data.message); + bool _isDataInitialized = true; + + Future setValues() async { + if (_isDataInitialized) { + combinedList.clear(); + combinedListGlobal.clear(); + combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost); + combinedList.addAll(feedpostobj!.data!.pinnedUserPost); + combinedList.addAll(feedpostobj!.data!.pinnedTagsPost); + combinedListGlobal.addAll(combinedList); + _setModel(); + countersHelper.setListsPopular(); + + await _fetchIcons(); + + _isDataInitialized = false; } } - saveunsavepost(int latestpostid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": latestpostid, - }; - final data = await Communitypostmethod().postUserSave(updata); - if (data.status == ResponseStatus.SUCCESS) { - FeedpostApi().getFeedPostApi().then((value) { - _initializeData(); - setState(() {}); - }); + _sortTags(index) { + var tags = commonobjmodel!.data[index].attachTags + .where((tag) => tag.manageTag?.name?.isNotEmpty ?? false) + .map((tag) => tag.manageTag!) + .toList(); - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } + return tags; } - pinunpinUser(int userid) async { - // utils.loader(); - Map updata = { - "pin_iam_principal_xid": userid, - }; - final data = await SidebarTags().postUserpin(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - FeedpostApi().getFeedPostApi().then((value) { - _initializeData(); - setState(() {}); - }); - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } + _setModel() { + commonobjmodel = null; + commonobjmodel = CommonDatumObjModel( + status: feedpostobj!.status, + statusCode: feedpostobj!.statusCode, + message: feedpostobj!.message, + data: combinedList + .map((e) => CommonDatumObjModelData( + id: e.id, + likecount: e.likecount, + isISaved: e.isISaved, + tagsXid: e.tagsXid, + isILiked: e.isILiked, + totalComment: e.totalComment, + totalSave: e.totalSave, + iamPrincipalXid: e.iamPrincipalXid, + postIn: e.postIn, + caption: e.caption, + image: e.image, + manageTagsXids: e.manageTagsXids, + postAs: e.postAs, + ctaTitle: e.ctaTitle, + ctaLink: e.ctaLink, + createdAt: e.createdAt, + likeIcon: LikeIcon1( + likeIcon: LikeIconClass1( + id: e.likeIcon?.likeIcon?.id, + image: e.likeIcon?.likeIcon?.image), + likeIconsXid: e.likeIcon?.likeIconsXid, + ), + totalViewCount: e.totalViewCount, + totalReactionCount: e.totalReactionCount, + totalCommentCount: e.totalCommentCount, + totalImpressionCount: e.totalImpressionCount, + totalPopularScore: e.totalPopularScore, + totalHoursAgo: e.totalHoursAgo, + iamPrincipal: IamPrincipal( + id: e.iamPrincipal!.id, + isUserPinned: e.iamPrincipal!.isUserPinned, + principalTypeXid: e.iamPrincipal!.principalTypeXid, + userName: e.iamPrincipal!.userName, + fullName: e.iamPrincipal!.fullName, + profilePhoto: e.iamPrincipal!.profilePhoto), + community: Community( + id: e.community!.id, + communityProfilePhoto: e.community!.communityProfilePhoto, + communityName: e.community!.communityName), + attachTags: e.attachTags + .map((e) => AttachTag1( + managePostXid: e.managePostXid, + manageTagXid: e.manageTagXid, + manageTag: ManageTagPopular( + id: e.manageTag?.id, + isPinned: e.manageTag?.isPinned, + name: e.manageTag?.name))) + .toList())) + .toList()); } @override @@ -435,7 +375,7 @@ class _FeedTabState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - "No Data Found", + "No posts are currently pinned", style: TextStyle( color: Colors.white, fontSize: 16.sp, @@ -446,1332 +386,36 @@ class _FeedTabState extends State { ) : Column( children: [ - sizedBoxHeight(16.h), + sizedBoxHeight(20.h), Expanded( child: ListView.builder( shrinkWrap: true, - itemCount: combinedList.length, + itemCount: commonobjmodel!.data.length, itemBuilder: (context, index) { var timeAgo = ConvertServerDateToUserDate() .convertServerDateToReadableFormate( - combinedList[index].createdAt.toString()); - var postId = combinedList[index].id; - var selectedReaction = _selectedReactions[postId]; - if (index == 1) { - return - // announcecardtile( - // profileImg: combinedList[index] - // .iamPrincipal! - // .profilePhoto ?? - // '', - // title: combinedList[index] - // .iamPrincipal! - // .fullName ?? - // '', - // mainImg: combinedList[index].image ?? '', - // containerTitle: [], - // // combinedList[index].attachTags[index].manageTag.name ?? [''], - // create_at: timeAgo, - // community_name: combinedList[index] - // .community! - // .communityName ?? - // '', - // totalcomments: combinedList[index] - // .totalComment - // .toString(), - // description: - // combinedList[index].caption ?? '', - // totalSave: - // combinedList[index].totalSave.toString(), - // ); + commonobjmodel!.data[index].createdAt + .toString()); - Column( - children: [ - commonGlassUIBlue( - width: double.infinity, - height: 840.h, - borderRadius: BorderRadius.circular(1), - customWidget: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - sizedBoxHeight(25.h), - Padding( - padding: - EdgeInsets.only(left: 16.w), - child: text16w700_FCFCFC( - "#Announcement"), - ), - sizedBoxHeight(25.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - CircleAvatar( - foregroundImage: NetworkImage( - combinedList[index] - .iamPrincipal! - .profilePhoto ?? - ''), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - text16w400_FCFCFC( - combinedList[index] - .iamPrincipal! - .fullName ?? - ''), - sizedBoxHeight(5.h), - Row( - children: [ - Image.asset( - 'assets/images/png/community 1 (traced).png', - height: 14.w, - width: 14.w, - ), - sizedBoxWidth(7.w), - text12w400_FCFCFC( - combinedList[ - index] - .community! - .communityName ?? - ''), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color( - 0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC( - timeAgo), - ], - ) - ], - ), - const Spacer(), - PopupMenuButton( - surfaceTintColor: - const Color(0xFF222935), - constraints: - BoxConstraints.tightFor( - width: 176.w), - offset: const Offset(0, 50), - color: - const Color(0xFF222935), - tooltip: "", - itemBuilder: (BuildContext - context) => - [ - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Report Post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/Vector (5).png", - height: 15.h, - width: 15.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Share post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/share.png", - height: 20.h, - width: 20.w, - ) - ], - ), - ), - ), - ], - child: Image.asset( - 'assets/images/png/Group 1000004071.png', - width: 16.w, - height: 18.h, - ), - ), - sizedBoxWidth(5.w) - ], - ), - ), - sizedBoxHeight(20.h), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName.postdetailsScreen, - arguments: { - "PostId": - combinedList[index] - .id - .toString() - }, - ); - }, - child: Container( - height: 390.h, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - combinedList[index] - .image ?? - '', - ), - fit: BoxFit.cover)), - ), - ), - sizedBoxHeight(20.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Column(children: [ - SizedBox( - height: 30.h, - width: double.infinity, - child: ListView.builder( - scrollDirection: - Axis.horizontal, - shrinkWrap: true, - // Filter the tags to include only those with a non-null and non-empty name - itemCount: combinedList[ - index] - .attachTags - .where((tag) => - tag.manageTag?.name - ?.isNotEmpty ?? - false) - .length, - itemBuilder: - (context, tagIndex) { - // Filtered list of tags - var filteredTags = - combinedList[index] - .attachTags - .where((tag) => - tag - .manageTag - ?.name - ?.isNotEmpty ?? - false) - .toList(); - - // Safely get the manageTag object - var manageTag = - filteredTags[tagIndex] - .manageTag; - - // Get the tag name, ensuring it's not null or empty - String tagName = - manageTag?.name ?? ''; - - return Padding( - padding: - EdgeInsets.only( - right: 12.w, - left: 12.w), - child: GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .tagdetailscreen, - arguments: { - 'tagid': - // filteredTags[ - // tagIndex] - // .manageTagXid, - combinedList[ - index] - .attachTags[ - tagIndex] - .manageTag! - .id, - 'tagname': - tagName, - 'ispinnedtag': filteredTags[ - tagIndex] - .manageTag! - .isPinned - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .start, - children: [ - commonContainer( - width: 130.w, - height: 30.h, - borderRadius: - BorderRadius - .circular( - 30.r), - borderColor: - const Color( - 0xFFD90B2E), - opacity1: 0.04, - opacity2: 0.05, - customWidget: - Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 10.w), - child: Center( - child: text14w400_FCFCFC( - '#${tagName}'), - ), - ), - ), - ], - ), - ), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - height: 80.h, - width: double.infinity, - child: SingleChildScrollView( - child: text16w400_FCFCFC( - combinedList[index] - .caption ?? - ''), - ), - ), - Row(children: [ - InkWell( - onTap: () {}, - child: stackReaction( - number: - combinedList[index] - .likecount - .toString(), - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), - ), - const Spacer(), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 13.h, - width: 13.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - combinedList[index] - .totalComment - .toString()), - sizedBoxWidth(20.w), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Vector (1).png', - height: 12.h, - width: 12.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - combinedList[index] - .totalSave - .toString()), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceAround, - children: [ - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Column( - children: [ - ReactionButton< - String>( - onReactionChanged: - (reaction) async { - if (selectedReaction != - null && - reaction?.value == - selectedReaction - .id - .toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange( - selectedReaction, - combinedList[ - index] - .id!); - } else { - // User selected a new reaction - var newSelectedReaction = - _reactions - .firstWhere( - (r) => - r.id.toString() == - reaction - ?.value, - orElse: () => - _reactions - .first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, - combinedList[ - index] - .id!); - } - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactions: - _reactions - .map((reaction) => - Reaction< - String>( - value: - reaction.id.toString(), - previewIcon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - icon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - )) - .toList(), - selectedReaction: - selectedReaction != - null - ? Reaction< - String>( - value: selectedReaction - .id - .toString(), - icon: - Image.network( - selectedReaction.image, - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ) - : Reaction< - String>( - value: - '', - icon: - Image.asset( - 'assets/images/png/uiw_like-o.png', - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ), - boxColor: - Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: - const Size( - 30, 30), - boxPadding: - const EdgeInsets - .all(8), - boxAnimationDuration: - const Duration( - milliseconds: - 200), - itemAnimationDuration: - const Duration( - milliseconds: - 500), - hoverDuration: - const Duration( - milliseconds: - 700), - child: selectedReaction != - null - ? Image - .network( - selectedReaction - .image, - width: 24, - height: - 24, - fit: BoxFit - .cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: - 24, - fit: BoxFit - .cover, - ), - ), - sizedBoxHeight(2.h), - text11w400_FCFCFC( - 'Like'), - ], - ) - ], - ), - GestureDetector( - onTap: () {}, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Comment') - ], - ), - ), - Column( - children: [ - GestureDetector( - onTap: () async { - int latestpostid = - combinedList[ - index] - .id!; - await saveunsavepost( - latestpostid); - }, - child: combinedList![ - index] - .isISaved == - true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: 19.h, - width: 19.w, - ), - ), - // Image.asset( - // 'assets/images/png/Frame 1000004089.png', - // height: 19.h, - // width: 19.w, - // ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Save') - ], - ) - ], - ), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - ]), - ), - ], - )), - sizedBoxHeight(20.h), - ], - ); - } else { - return Column( - children: [ - commonGlassUI( - width: double.infinity, - height: 760.h, - mainOpacity: 1, - borderRadius: BorderRadius.circular(1), - customWidget: Column( - children: [ - sizedBoxHeight(25.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - CircleAvatar( - foregroundImage: NetworkImage( - combinedList[index] - .iamPrincipal! - .profilePhoto ?? - ''), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - text16w400_FCFCFC( - combinedList[index] - .iamPrincipal! - .fullName ?? - ''), - sizedBoxHeight(5.h), - Row( - children: [ - Image.asset( - 'assets/images/png/community 1 (traced).png', - height: 14.w, - width: 14.w, - ), - sizedBoxWidth(7.w), - text12w400_FCFCFC( - combinedList[ - index] - .community! - .communityName ?? - ''), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color( - 0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC( - timeAgo!), - ], - ) - ], - ), - const Spacer(), - PopupMenuButton( - surfaceTintColor: - const Color(0xFF222935), - constraints: - BoxConstraints.tightFor( - width: 176.w), - offset: const Offset(0, 50), - color: - const Color(0xFF222935), - tooltip: "", - itemBuilder: (BuildContext - context) => - [ - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Report Post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/Vector (5).png", - height: 15.h, - width: 15.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Share post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/share.png", - height: 20.h, - width: 20.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () async { - int pinPospostid = - combinedList[ - index] - .iamPrincipal! - .id!; - await pinunpinUser( - pinPospostid); - }, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - combinedList[index] - .iamPrincipal! - .isUserPinned == - true - ? 'Unpin' - : 'Pin', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 25.h, - width: 25.w, - ) - ], - ), - ), - ), - ], - child: Image.asset( - 'assets/images/png/Group 1000004071.png', - width: 16.w, - height: 18.h, - ), - ), - sizedBoxWidth(5.w) - ], - ), - ), - sizedBoxHeight(20.h), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName.postdetailsScreen, - arguments: { - "PostId": - combinedList[index] - .id - .toString() - }); - }, - child: Container( - height: 360, - width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.cover, - image: NetworkImage( - combinedList[index] - .image ?? - '', - ), - ), - ), - ), - ), - sizedBoxHeight(20.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Column(children: [ - SizedBox( - height: 30.h, - width: double.infinity, - child: ListView.builder( - scrollDirection: - Axis.horizontal, - shrinkWrap: true, - // Filter the tags to include only those with a non-null and non-empty name - itemCount: combinedList[ - index] - .attachTags - .where((tag) => - tag.manageTag?.name - ?.isNotEmpty ?? - false) - .length, - itemBuilder: - (context, tagIndex) { - // Filtered list of tags - var filteredTags = - combinedList[index] - .attachTags - .where((tag) => - tag - .manageTag - ?.name - ?.isNotEmpty ?? - false) - .toList(); - - // Safely get the manageTag object - var manageTag = - filteredTags[tagIndex] - .manageTag; - - // Get the tag name, ensuring it's not null or empty - String tagName = - manageTag?.name ?? ''; - - return Padding( - padding: - EdgeInsets.only( - right: 12.w, - left: 12.w), - child: GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .tagdetailscreen, - arguments: { - 'tagid': combinedList[ - index] - .attachTags[ - tagIndex] - .manageTag! - .id, - 'tagname': - tagName, - 'ispinnedtag': filteredTags[ - tagIndex] - .manageTag! - .isPinned - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .start, - children: [ - commonContainer( - width: 130.w, - height: 30.h, - borderRadius: - BorderRadius - .circular( - 30.r), - borderColor: - const Color( - 0xFFD90B2E), - opacity1: 0.04, - opacity2: 0.05, - customWidget: - Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 10.w), - child: Center( - child: text14w400_FCFCFC( - '#${tagName}'), - ), - ), - ), - ], - ), - ), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - height: 80.h, - width: double.infinity, - child: SingleChildScrollView( - child: text16w400_FCFCFC( - combinedList![index] - .caption ?? - ''), - ), - ), - sizedBoxHeight(20.h), - Row(children: [ - InkWell( - onTap: () { - Get.toNamed(RouteName - .reactionview); - }, - child: stackReaction( - number: - combinedList[index] - .likecount - .toString(), - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), - ), - const Spacer(), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 13.h, - width: 13.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - combinedList![index] - .totalComment - .toString()), - sizedBoxWidth(20.w), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Vector (1).png', - height: 12.h, - width: 12.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - combinedList![index] - .totalSave - .toString()), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceAround, - children: [ - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Column( - children: [ - ReactionButton< - String>( - onReactionChanged: - (reaction) async { - if (selectedReaction != - null && - reaction?.value == - selectedReaction - .id - .toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange( - selectedReaction, - combinedList[ - index] - .id!); - } else { - // User selected a new reaction - var newSelectedReaction = - _reactions - .firstWhere( - (r) => - r.id.toString() == - reaction - ?.value, - orElse: () => - _reactions - .first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, - combinedList[ - index] - .id!); - } - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactions: - _reactions - .map((reaction) => - Reaction< - String>( - value: - reaction.id.toString(), - previewIcon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - icon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - )) - .toList(), - selectedReaction: - selectedReaction != - null - ? Reaction< - String>( - value: selectedReaction - .id - .toString(), - icon: - Image.network( - selectedReaction.image, - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ) - : Reaction< - String>( - value: - '', - icon: - Image.asset( - 'assets/images/png/uiw_like-o.png', - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ), - boxColor: - Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: - const Size( - 30, 30), - boxPadding: - const EdgeInsets - .all(8), - boxAnimationDuration: - const Duration( - milliseconds: - 200), - itemAnimationDuration: - const Duration( - milliseconds: - 500), - hoverDuration: - const Duration( - milliseconds: - 700), - child: selectedReaction != - null - ? Image - .network( - selectedReaction - .image, - width: 24, - height: - 24, - fit: BoxFit - .cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: - 24, - fit: BoxFit - .cover, - ), - ), - sizedBoxHeight(2.h), - text11w400_FCFCFC( - 'Like'), - ], - ) - ], - ), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .postdetailsScreen, - arguments: { - "PostId": - combinedList[ - index] - .id - .toString() - }); - }, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Comment') - ], - ), - ), - InkWell( - onTap: () {}, - child: Column( - children: [ - GestureDetector( - onTap: () async { - int latestpostid = - combinedList[ - index] - .id!; - await saveunsavepost( - latestpostid); - }, - child: combinedList[ - index] - .isISaved == - true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: - 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: - 19.h, - width: 19.w, - ), - ), - // Image.asset( - // 'assets/images/png/Frame 1000004089.png', - // height: 19.h, - // width: 19.w, - // ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Save') - ], - ), - ), - ], - ), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - ]), - ), - ], - )), - sizedBoxHeight(20.h) - ], - ); - - // Column( - // children: [ - // // normalcardtile2( - // // profileImg: combinedList[index] - // // .iamPrincipal! - // // .profilePhoto ?? - // // '', - // // title: combinedList[index] - // // .iamPrincipal! - // // .fullName ?? - // // '', - // // mainImg: combinedList[index].image ?? '', - // // containerTitle: - // // combinedList[index].tagNames ?? [], - // // description: - // // combinedList[index].caption ?? '', - // // create_at: timeAgo, - // // total_comments: combinedList[index] - // // .totalComment - // // .toString(), - // // total_likes: combinedList[index] - // // .likecount - // // .toString(), - // // total_save: combinedList[index] - // // .totalSave - // // .toString(), - // // community_name: combinedList[index] - // // .community! - // // .communityName - // // .toString(), - // // RecationId: - // // combinedList[index].id.toString(), - // // ), - - // sizedBoxHeight(20.h) - // ], - // ); - } + 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) + ], + ); }, ), ), ], - ), + ) ], ); } @@ -1781,50 +425,25 @@ class _FeedTabState extends State { } } +// ignore: must_be_immutable class NormalCardTile extends StatefulWidget { - final String profileImg; - final String title; - final String mainImg; - final String description; - // final List containerTitle; - final List tags; - final String community_name; - final String total_comments; - final String total_likes; - final String total_save; - final String? create_at; - final String? postId; - final void Function()? onSaveIconTap; - final bool? isISaved; - // final dynamic commonpostobj; - final void Function(Reaction?) onReactionChangedLike; - final List?> reactionsLike; - final Reaction? selectedReactionLike; - final Widget? likePopupWidget; - final void Function()? mainImagetap; + List tags; + String? create_at; + CommonDatumObjModelData commonObj; + String forWhichTab; + List reactions; + Map selectedReactions; - const NormalCardTile({ + int currentIndex; + NormalCardTile({ Key? key, - required this.profileImg, - required this.title, - required this.mainImg, - required this.description, - // required this.containerTitle, required this.tags, - required this.community_name, - required this.total_comments, - required this.total_likes, - required this.total_save, - // this.commonpostobj, - required this.onReactionChangedLike, - required this.reactionsLike, - required this.selectedReactionLike, - required this.likePopupWidget, - required this.mainImagetap, this.create_at, - this.postId, - this.onSaveIconTap, - this.isISaved, + required this.forWhichTab, + required this.commonObj, + required this.reactions, + required this.selectedReactions, + required this.currentIndex, }) : super(key: key); @override @@ -1833,138 +452,130 @@ class NormalCardTile extends StatefulWidget { class _NormalCardTileState extends State { RxString mainImage = 'assets/images/png/uiw_like-o.png'.obs; + final CountersHelper countersHelper = Get.find(); + int saveCount = 0; + _handleReactionChange(Reaction? reaction) async { + if (widget.selectedReactions[widget.commonObj.id] != null && + reaction?.value == + widget.selectedReactions[widget.commonObj.id]!.id.toString() || + reaction?.value == null) { + // User tapped on the currently selected reaction, so remove it - void updateImage(String reaction) { - if (reaction == 'like') { - mainImage.value = 'assets/images/png/f7_hand-thumbsup.png'; - } else if (reaction == 'heart') { - mainImage.value = 'assets/images/png/heart 2.png'; - } else if (reaction == 'party') { - mainImage.value = 'assets/images/png/party-popper 2.png'; + //api call for dislike + + await LikeUploaddata( + widget.selectedReactions[widget.commonObj.id]?.id, + widget.commonObj.id!, + ); + setState(() { + widget.selectedReactions[widget.commonObj.id!] = null; + //decrement gloally + countersHelper.likesCounterPopular[widget.currentIndex]--; + log("global value ${countersHelper.likesCounterPopular[widget.currentIndex]}"); + }); + } else { + // User selected a new reaction + var newSelectedReaction = widget.reactions.firstWhere( + (r) => r.id.toString() == reaction?.value, + orElse: () => widget.reactions.first, // Default reaction if not found + ); + await _handleReactionChangeApiCall( + newSelectedReaction, widget.commonObj.id!); } } - // List _reactions = []; - // Map _selectedReactions = {}; + Future _handleReactionChangeApiCall( + ReactionData? reaction, int postId) async { + setState(() { + widget.selectedReactions[postId] = + reaction; // Set the selected reaction for this post - // Future _initializeData() async { - // await _fetchIcons(); + if (countersHelper.likesCounterPopular[widget.currentIndex] <= + widget.commonObj.totalReactionCount!) { + countersHelper.likesCounterPopular[widget.currentIndex]++; + } + }); - // for (var post in widget.commonpostobj) { - // if (post.likeIcon != null) { - // likeIconIdnew = post.likeIcon!.likeIconsXid ?? 0; - // } else { - // likeIconIdnew = 0; // Handle it as needed - // } - // _initializeSelectedReaction(post.id); // Pass the post ID - // } - // } + await LikeUploaddata( + reaction?.id, + postId, + ); + } - // Future _fetchIcons() async { - // var response = await Communityallgetmethod().getLikeicons(); - // if (response.status == ResponseStatus.SUCCESS) { - // var responseData = response.data as Map; - // FetchlikeIconsModel fetchlikeIconsModel = - // FetchlikeIconsModel.fromJson(responseData); + LikeUploaddata(int? likeIconId, int? postid) async { + Map updata = { + "manage_posts_xid": postid, + "like_icons_xid": likeIconId ?? '', + }; + final data = await CommunitypostMethod().postLikepost(updata); + if (data.status == ResponseStatus.SUCCESS) { + // return utils.showToast(data.message); + } else { + return utils.showToast(data.message); + } + } - // setState(() { - // _reactions = fetchlikeIconsModel.data - // ?.map((data) => ReactionData( - // id: data.id!, - // image: data.image!, - // )) - // .toList() ?? - // []; - // for (var post in latestpostobj!.data) { - // _initializeSelectedReaction(post.id!); - // } - // }); - // } - // } + void updateImage(String reaction) { + switch (reaction) { + case 'like': + mainImage.value = 'assets/images/png/f7_hand-thumbsup.png'; + break; + case 'heart': + mainImage.value = 'assets/images/png/heart 2.png'; + break; + case 'party': + mainImage.value = 'assets/images/png/party-popper 2.png'; + break; + default: + // Handle any other cases or do nothing + break; + } + } - // int? likeIconIdnew; + saveunsavepost(int popularpostid) async { + // utils.loader(); + Map updata = { + "manage_posts_xid": popularpostid, + }; + final data = await Communitypostmethod().postUserSave(updata); + if (data.status == ResponseStatus.SUCCESS) { + if (countersHelper.saveButtonPopular[widget.currentIndex] == false) { + countersHelper.savePostCounterPopular[widget.currentIndex]++; + } else { + countersHelper.savePostCounterPopular[widget.currentIndex]--; + } + countersHelper.saveButtonPopular[widget.currentIndex] = + !countersHelper.saveButtonPopular[widget.currentIndex]; + return utils.showToast(data.message); + } else { + return utils.showToast(data.message); + } + } - // void _initializeSelectedReaction(int postId) { - // // Check if there's a stored likeIconId for this post - // if (likeIconIdnew != null && likeIconIdnew != 0 && _reactions.isNotEmpty) { - // final selectedReaction = _reactions.firstWhere( - // (r) => r.id == likeIconIdnew, - // orElse: () => _reactions.first, - // ); + pinunpinUser(int userid) async { + Map updata = { + "pin_iam_principal_xid": userid, + }; + final data = await SidebarTags().postUserpin(updata); + if (data.status == ResponseStatus.SUCCESS) { + countersHelper.pinButtonPopular[widget.currentIndex] = + !countersHelper.pinButtonPopular[widget.currentIndex]; + return utils.showToast(data.message); + } else { + return utils.showToast(data.message); + } + } - // setState(() { - // _selectedReactions[postId] = - // selectedReaction; // Set selected reaction for this post - // print( - // 'Selected reaction for post $postId is ${_selectedReactions[postId].toString()}'); - // log(_selectedReactions[postId].toString()); - // }); - // } else { - // setState(() { - // _selectedReactions[postId] = null; // No reaction selected - // print('No reaction selected for post $postId'); - // }); - // } - // } - - // Future _handleReactionChange(ReactionData? reaction, int postId) async { - // // Check if the postId is valid - // if (postId == null) return; - - // setState(() { - // if (reaction == null) { - // _selectedReactions[postId] = - // null; // Mark reaction as removed for this post - // } else { - // _selectedReactions[postId] = - // reaction; // Set the selected reaction for this post - // } - // }); - - // try { - // await LikeUploaddata( - // reaction?.id, - // postId, - // ); - // } catch (error) { - // print('Error updating reaction: $error'); - // setState(() { - // _selectedReactions[postId] = - // reaction; // Restore previous reaction if needed - // }); - // } - // } - - // LikeUploaddata(int? likeIconId, int? postid) async { - // // utils.loader(); - // Map updata = { - // "manage_posts_xid": postid, - // "like_icons_xid": likeIconId ?? '', - // }; - // final data = await CommunitypostMethod().postLikepost(updata); - // if (data.status == ResponseStatus.SUCCESS) { - // // Get.back(); - // print("like done"); - // return utils.showToast(data.message); - // } else { - // // Get.back(); - // print("like not done"); - // return utils.showToast(data.message); - // } - // } - - // @override - // void initState() async { - // // TODO: implement initState - // await _initializeData(); - // super.initState(); - // } + @override + void initState() { + super.initState(); + } @override Widget build(BuildContext context) { return commonGlassUI( width: double.infinity, - height: 760.h, + height: 765.h, mainOpacity: 1, borderRadius: BorderRadius.circular(1), customWidget: Column( @@ -1976,14 +587,16 @@ class _NormalCardTileState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( - foregroundImage: NetworkImage(widget.profileImg), + foregroundImage: NetworkImage( + widget.commonObj.iamPrincipal!.profilePhoto!), radius: 25.r, ), sizedBoxWidth(12.w), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - text16w400_FCFCFC(widget.title), + text16w400_FCFCFC( + widget.commonObj.iamPrincipal!.fullName ?? "Regroup"), sizedBoxHeight(5.h), Row( children: [ @@ -1993,7 +606,8 @@ class _NormalCardTileState extends State { width: 14.w, ), sizedBoxWidth(7.w), - text12w400_FCFCFC(widget.community_name), + text12w400_FCFCFC( + widget.commonObj.community!.communityName ?? ""), sizedBoxWidth(7.w), Icon( Icons.circle, @@ -2067,26 +681,46 @@ class _NormalCardTileState extends State { ), const PopupMenuDivider(), PopupMenuItem( - onTap: () {}, + onTap: () { + pinunpinUser(widget.commonObj.iamPrincipal!.id!); + }, child: Padding( padding: EdgeInsets.symmetric(horizontal: 12.w), child: Row( children: [ - Text( - 'Pin', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", - ), - ), + countersHelper + .pinButtonPopular[widget.currentIndex] + ? Text( + 'Unpin', + style: TextStyle( + fontSize: 16.sp, + color: Colors.white, + fontWeight: FontWeight.w800, + fontFamily: "Nunito Sans", + ), + ) + : Text( + 'Pin', + style: TextStyle( + fontSize: 16.sp, + color: Colors.white, + fontWeight: FontWeight.w800, + fontFamily: "Nunito Sans", + ), + ), const Spacer(), - Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 25.h, - width: 25.w, - ) + countersHelper + .pinButtonPopular[widget.currentIndex] + ? Image.asset( + "assets/images/png/PinnedIcon.png", + height: 25.h, + width: 25.w, + ) + : Image.asset( + "assets/images/png/f7_pin-fill (2).png", + height: 25.h, + width: 25.w, + ) ], ), ), @@ -2104,20 +738,37 @@ class _NormalCardTileState extends State { ), sizedBoxHeight(20.h), GestureDetector( - onTap: widget.mainImagetap, - child: Container( - height: 360, - width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( + onTap: () async { + bool result = await Get.toNamed(RouteName.postdetailsScreen, + arguments: { + 'postId': widget.commonObj.id, + 'tagsList': widget.tags, + 'created_at': widget.create_at, + 'commonObj': widget.commonObj, + 'fromWhichTab': widget.forWhichTab, + 'reactions': widget.reactions, + 'selectedReactions': widget.selectedReactions, + 'currentIndex': widget.currentIndex + }); + if (result) { + setState(() {}); + } + }, + child: Container( + height: 360, + width: double.infinity, + child: CachedNetworkImage( + // cacheKey: "1st", + imageUrl: widget.commonObj.image!, fit: BoxFit.cover, - image: NetworkImage( - widget.mainImg, - ), + placeholder: (context, url) => const Center( + child: + CircularProgressIndicator()), // Optional: shows a loading indicator while the image is loading + errorWidget: (context, url, error) => const Center( + child: Icon(Icons + .error)), // Optional: shows an error icon if the image fails to load ), - ), - ), - ), + )), sizedBoxHeight(20.h), Padding( padding: EdgeInsets.symmetric(horizontal: 16.w), @@ -2172,23 +823,27 @@ class _NormalCardTileState extends State { height: 80.h, width: double.infinity, child: SingleChildScrollView( - child: text16w400_FCFCFC(widget.description)), + child: text16w400_FCFCFC(widget.commonObj.caption ?? "")), ), sizedBoxHeight(20.h), Row(children: [ - InkWell( - onTap: () { - Get.toNamed(RouteName.reactionview, arguments: { - 'postId': widget.postId, - }); - }, - child: stackReaction( - number: widget.total_likes, - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), + Obx( + () => InkWell( + onTap: () { + Get.toNamed(RouteName.reactionview, arguments: { + 'postId': widget.commonObj.id, + }); + }, + child: stackReaction( + number: countersHelper + .likesCounterPopular[widget.currentIndex] + .toString(), + containerImages: [ + 'assets/images/png/f7_hand-thumbsup.png', + 'assets/images/png/heart 2.png', + 'assets/images/png/party-popper 2.png' + ]), + ), ), const Spacer(), commonContainer( @@ -2208,7 +863,8 @@ class _NormalCardTileState extends State { ), ), sizedBoxWidth(12.w), - text14w400_FCFCFC(widget.total_comments), + text14w400_FCFCFC( + widget.commonObj.totalCommentCount.toString()), sizedBoxWidth(20.w), commonContainer( width: 30.w, @@ -2227,7 +883,11 @@ class _NormalCardTileState extends State { ), ), sizedBoxWidth(12.w), - text14w400_FCFCFC(widget.total_save), + Obx( + () => text14w400_FCFCFC(countersHelper + .savePostCounterPopular[widget.currentIndex] + .toString()), + ), ]), sizedBoxHeight(12.h), commonDivider(), @@ -2239,68 +899,45 @@ class _NormalCardTileState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ ReactionButton( - onReactionChanged: widget.onReactionChangedLike, - // (reaction) async { - // if (_selectedReactions[postId] != null && - // reaction?.value == - // _selectedReactions[postId]!.id.toString()) { - // // User tapped on the currently selected reaction, so remove it - // await _handleReactionChange( - // _selectedReactions[postId], postId as int); - // } else { - // // User selected a new reaction - // var newSelectedReaction = _reactions.firstWhere( - // (r) => r.id.toString() == reaction?.value, - // orElse: () => _reactions - // .first, // Default reaction if not found - // ); - // await _handleReactionChange( - // newSelectedReaction, postId as int); - // } - // debugPrint('Selected value: ${reaction?.value}'); - // }, - reactions: widget.reactionsLike, - - // _reactions - // .map((reaction) => Reaction( - // value: reaction.id.toString(), - // previewIcon: Image.network(reaction.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover), - // icon: Image.network(reaction.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover), - // )) - // .toList(), - selectedReaction: widget.selectedReactionLike, - - // _selectedReactions[postId] != null - // ? Reaction( - // value: - // _selectedReactions[postId]!.id.toString(), - // icon: Image.network( - // _selectedReactions[postId]!.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), - // ) - // : Reaction( - // value: '', - // icon: Image.asset( - // 'assets/images/png/uiw_like-o.png', - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), - // ), + onReactionChanged: (reaction) async { + _handleReactionChange(reaction); + }, + reactions: widget.reactions + .map((reaction) => Reaction( + value: reaction.id.toString(), + previewIcon: Image.network(reaction.image, + width: 24, + height: 24, + fit: BoxFit.cover), + icon: Image.network(reaction.image, + width: 24, + height: 24, + fit: BoxFit.cover), + )) + .toList(), + selectedReaction: widget + .selectedReactions[widget.commonObj.id] != + null + ? Reaction( + value: widget + .selectedReactions[widget.commonObj.id]! + .id + .toString(), + icon: Image.network( + widget + .selectedReactions[widget.commonObj.id]! + .image, + width: 24, + height: 24, + fit: BoxFit.cover, + ), + ) + : null, boxColor: Colors.white, boxElevation: 9, boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, + itemsSpacing: 20, + itemScale: 0.3, itemSize: const Size(30, 30), boxPadding: const EdgeInsets.all(8), boxAnimationDuration: @@ -2308,31 +945,45 @@ class _NormalCardTileState extends State { itemAnimationDuration: const Duration(milliseconds: 500), hoverDuration: const Duration(milliseconds: 700), - child: widget.likePopupWidget, - - // _selectedReactions[postId] != null - // ? Image.network( - // _selectedReactions[postId]!.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ) - // : Image.asset( - // 'assets/images/png/uiw_like-o.png', - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), + child: widget + .selectedReactions[widget.commonObj.id] != + null + ? Image.network( + widget.selectedReactions[widget.commonObj.id]! + .image, + width: 24, + height: 24, + fit: BoxFit.cover, + ) + : Image.asset( + 'assets/images/png/uiw_like-o.png', + width: 24, + height: 24, + fit: BoxFit.cover, + ), ), sizedBoxHeight(8.h), text11w400_FCFCFC('Like'), ], ), GestureDetector( - onTap: widget.mainImagetap, - // onTap: () { - // Get.toNamed(RouteName.postdetailsScreen, ); - // }, + onTap: () async { + bool result = await Get.toNamed( + RouteName.postdetailsScreen, + arguments: { + 'postId': widget.commonObj.id, + 'tagsList': widget.tags, + 'created_at': widget.create_at, + 'commonObj': widget.commonObj, + 'fromWhichTab': widget.forWhichTab, + 'reactions': widget.reactions, + 'selectedReactions': widget.selectedReactions, + 'currentIndex': widget.currentIndex + }); + if (result) { + setState(() {}); + } + }, child: Column( children: [ Image.asset( @@ -2345,25 +996,30 @@ class _NormalCardTileState extends State { ], ), ), - Column( - children: [ - GestureDetector( - onTap: widget.onSaveIconTap, - child: widget.isISaved == true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: 19.h, - width: 19.w, - ), - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Save') - ], + Obx( + () => Column( + //here + children: [ + GestureDetector( + onTap: () async => + await saveunsavepost(widget.commonObj.id!), + child: countersHelper + .saveButtonPopular[widget.currentIndex] + ? Image.asset( + 'assets/images/png/postSaved.png', + height: 19.h, + width: 19.w, + ) + : Image.asset( + 'assets/images/png/Frame 1000004089.png', + height: 19.h, + width: 19.w, + ), + ), + sizedBoxHeight(8.h), + text11w400_FCFCFC('Save') + ], + ), ), ], ), @@ -2377,31 +1033,6 @@ class _NormalCardTileState extends State { } } -Widget _buildReactionsPreviewIcon(String assetPath) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: Image.asset( - assetPath, - height: 40.h, - width: 40.w, - ), - ); -} - -Widget _buildReactionsIcon(String assetPath) { - return Column( - children: [ - Image.asset( - assetPath, - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Like') - ], - ); -} - Widget containertile({required String text}) { return commonGlassContainer( border: 1, @@ -2438,52 +1069,17 @@ class PopularTab extends StatefulWidget { class _PopularTabState extends State { late Future popularfuture; - - saveunsavepost(int popularpostid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": popularpostid, - }; - final data = await Communitypostmethod().postUserSave(updata); - if (data.status == ResponseStatus.SUCCESS) { - PopularpostApi().getPopularPostApi().then((value) { - _initializeData(); - setState(() {}); - }); - - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } - } - + List _reactions = []; + Map _selectedReactions = {}; + final CountersHelper countersHelper = Get.find(); + int? likeIconIdnew; @override void initState() { popularfuture = PopularpostApi().getPopularPostApi(); - // _initializeData(); - // TODO: implement initState + super.initState(); } -//reacttionlikelogic - - List _reactions = []; - Map _selectedReactions = {}; - - Future _initializeData() async { - await _fetchIcons(); - // _initializeSelectedReaction(); - for (var post in popularpostobj!.data) { - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; // This is safe now - } else { - likeIconIdnew = 0; // Or handle it as needed - } - _initializeSelectedReaction(post.id!); // Pass the post ID - } - } - Future _fetchIcons() async { var response = await Communityallgetmethod().getLikeicons(); if (response.status == ResponseStatus.SUCCESS) { @@ -2491,178 +1087,108 @@ class _PopularTabState extends State { FetchlikeIconsModel fetchlikeIconsModel = FetchlikeIconsModel.fromJson(responseData); - setState(() { - _reactions = fetchlikeIconsModel.data - ?.map((data) => ReactionData( - id: data.id!, - image: data.image!, - )) - .toList() ?? - []; - for (var post in popularpostobj!.data) { - _initializeSelectedReaction(post.id!); + _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, + ); + + _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'); } - }); - } - } - - int? likeIconIdnew; - - void _initializeSelectedReaction(int postId) { - // Check if there's a stored likeIconId for this post - if (likeIconIdnew != null && likeIconIdnew != 0 && _reactions.isNotEmpty) { - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - setState(() { - _selectedReactions[postId] = - selectedReaction; // Set selected reaction for this post - print( - 'Selected reaction for post $postId is ${_selectedReactions[postId].toString()}'); - log(_selectedReactions[postId].toString()); - }); - } else { - setState(() { - _selectedReactions[postId] = null; // No reaction selected - print('No reaction selected for post $postId'); - }); - } - } - - Future _handleReactionChange(ReactionData? reaction, int postId) async { - // Check if the postId is valid - if (postId == null) return; - - setState(() { - if (reaction == null) { - _selectedReactions[postId] = - null; // Mark reaction as removed for this post - } else { - _selectedReactions[postId] = - reaction; // Set the selected reaction for this post } - }); - - try { - await LikeUploaddata( - reaction?.id, - postId, - ); - } catch (error) { - print('Error updating reaction: $error'); - setState(() { - _selectedReactions[postId] = - reaction; // Restore previous reaction if needed - }); + setState(() {}); } } - LikeUploaddata(int? likeIconId, int? postid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": postid, - "like_icons_xid": likeIconId ?? '', - }; - final data = await CommunitypostMethod().postLikepost(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - print("like done"); - return utils.showToast(data.message); - } else { - // Get.back(); - print("like not done"); - return utils.showToast(data.message); - } - } - - List popularTabData = [ - { - "profileImg": "assets/images/png/Ellipse 43.png", - "title": "Edward Hackket", - "mainImg": "assets/images/png/Rectangle 24.png", - "containerTitle": ['Cycle', 'Marathon', 'Events', 'Marathon', 'Events'], - "desciption": "", - "create_at": '1 hour', - "total_comments": 20, - "total_likes": 20, - "total_save": 10, - "community_name": 'text', - }, - { - "profileImg": "assets/images/png/Ellipse 52.png", - "title": "Ryan Dorwat", - "mainImg": "assets/images/png/Rectangle 25.png", - "containerTitle": [ - 'Football', - 'Teams player', - 'Events', - 'Marathon', - 'Events' - ], - "desciption": "", - "create_at": '1 hour', - "total_comments": 20, - "total_likes": 20, - "total_save": 10, - "community_name": 'text', - }, - { - "profileImg": "assets/images/png/Ellipse 52.png", - "title": "Ryan Dorwat", - "mainImg": "assets/images/png/Rectangle 25.png", - "containerTitle": [ - 'Football', - 'Teams player', - 'Events', - 'Marathon', - 'Events' - ], - "desciption": "", - "create_at": '1 hour', - "total_comments": 20, - "total_likes": 20, - "total_save": 10, - "community_name": 'text', - }, - { - "profileImg": "assets/images/png/Ellipse 52.png", - "title": "Ryan Dorwat", - "mainImg": "assets/images/png/Rectangle 25.png", - "containerTitle": [ - 'Football', - 'Teams player', - 'Events', - 'Marathon', - 'Events' - ], - "desciption": "", - "create_at": '1 hour', - "total_comments": 20, - "total_likes": 20, - "total_save": 10, - "community_name": 'text', - }, - ]; - - bool _isDataInitialized = false; + bool _isDataInitialized = true; Future setValues() async { - if (_isDataInitialized) return; // Check if data is already initialized + if (_isDataInitialized) { + _setModel(); + countersHelper.setListsPopular(); + await _fetchIcons(); - try { - await _initializeData(); - - setState(() { - _isDataInitialized = true; - }); - } catch (e) { - // Handle any errors that occur during the fetch - print('Error fetching data: $e'); + _isDataInitialized = false; } } + _sortTags(index) { + var tags = commonobjmodel!.data[index].attachTags + .where((tag) => tag.manageTag?.name?.isNotEmpty ?? false) + .map((tag) => tag.manageTag!) + .toList(); + + return tags; + } + + _setModel() { + commonobjmodel = null; + commonobjmodel = CommonDatumObjModel( + status: popularpostobj!.status, + statusCode: popularpostobj!.statusCode, + message: popularpostobj!.message, + data: popularpostobj!.data + .map((e) => CommonDatumObjModelData( + id: e.id, + likecount: e.likecount, + isISaved: e.isISaved, + tagsXid: e.tagsXid, + isILiked: e.isILiked, + totalComment: e.totalComment, + totalSave: e.totalSave, + iamPrincipalXid: e.iamPrincipalXid, + postIn: e.postIn, + caption: e.caption, + image: e.image, + manageTagsXids: e.manageTagsXids, + postAs: e.postAs, + ctaTitle: e.ctaTitle, + ctaLink: e.ctaLink, + createdAt: e.createdAt, + likeIcon: LikeIcon1( + likeIcon: LikeIconClass1( + id: e.likeIcon?.likeIcon?.id, + image: e.likeIcon?.likeIcon?.image), + likeIconsXid: e.likeIcon?.likeIconsXid, + ), + totalViewCount: e.totalViewCount, + totalReactionCount: e.totalReactionCount, + totalCommentCount: e.totalCommentCount, + totalImpressionCount: e.totalImpressionCount, + totalPopularScore: e.totalPopularScore, + totalHoursAgo: e.totalHoursAgo, + iamPrincipal: IamPrincipal( + id: e.iamPrincipal!.id, + isUserPinned: e.iamPrincipal!.isUserPinned, + principalTypeXid: e.iamPrincipal!.principalTypeXid, + userName: e.iamPrincipal!.userName, + fullName: e.iamPrincipal!.fullName, + profilePhoto: e.iamPrincipal!.profilePhoto), + community: Community( + id: e.community!.id, + communityProfilePhoto: e.community!.communityProfilePhoto, + communityName: e.community!.communityName), + attachTags: e.attachTags + .map((e) => AttachTag1( + managePostXid: e.managePostXid, + manageTagXid: e.manageTagXid, + manageTag: ManageTagPopular( + id: e.manageTag?.id, + isPinned: e.manageTag?.isPinned, + name: e.manageTag?.name))) + .toList())) + .toList()); + } + @override Widget build(BuildContext context) { return FutureBuilder( @@ -2704,7 +1230,7 @@ class _PopularTabState extends State { child: Column( children: [ Text( - "No Data Found", + "No Posts Available", style: TextStyle( color: Colors.white, fontSize: 16.sp, @@ -2720,145 +1246,24 @@ class _PopularTabState extends State { Expanded( child: ListView.builder( shrinkWrap: true, - itemCount: popularpostobj!.data.length, + itemCount: commonobjmodel!.data.length, itemBuilder: (context, index) { - var popularData = popularpostobj!.data[index]; - var postId = popularpostobj!.data[index].id; - var selectedReaction = _selectedReactions[postId]; var timeAgo = ConvertServerDateToUserDate() .convertServerDateToReadableFormate( - popularData.createdAt.toString()); - var tags = popularData.attachTags - .where((tag) => - tag.manageTag?.name?.isNotEmpty ?? false) - .map((tag) => tag.manageTag!) - .toList(); + popularpostobj!.data[index].createdAt + .toString()); + return Column( children: [ NormalCardTile( - profileImg: popularData - .iamPrincipal!.profilePhoto ?? - popularTabData[index]["profileImg"], - title: popularData.iamPrincipal!.fullName ?? - popularTabData[index]["title"], - mainImg: popularData.image ?? - popularTabData[index]["mainImg"], - // containerTitle: [] ?? - // popularTabData[index]["containerTitle"], - tags: tags, - description: popularData.caption ?? 'test', + tags: _sortTags(index), create_at: timeAgo ?? '1 hour', - total_comments: popularData - .totalCommentCount - .toString() ?? - '20', - total_likes: popularData.totalReactionCount - .toString(), - total_save: - popularData.totalSave.toString() ?? - '10', - community_name: - popularData.community!.communityName ?? - 'text', - postId: popularData.id.toString(), - mainImagetap: () { - Get.toNamed(RouteName.postdetailsScreen, - arguments: { - "PostId": popularData.id.toString() - }); - }, - onSaveIconTap: () async { - await saveunsavepost(popularData.id!); - }, - isISaved: popularData.isISaved, - onReactionChangedLike: (reaction) async { - if (selectedReaction != null && - reaction?.value == - selectedReaction.id.toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange( - selectedReaction, - popularpostobj!.data[index].id!); - } else { - // User selected a new reaction - var newSelectedReaction = - _reactions.firstWhere( - (r) => - r.id.toString() == - reaction?.value, - orElse: () => _reactions - .first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, - popularpostobj!.data[index].id!); - } - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactionsLike: _reactions - .map((reaction) => Reaction( - value: reaction.id.toString(), - previewIcon: Image.network( - reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - icon: Image.network( - reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - )) - .toList(), - selectedReactionLike: selectedReaction != - null - ? Reaction( - value: - selectedReaction.id.toString(), - icon: Image.network( - selectedReaction.image, - width: 24, - height: 24, - fit: BoxFit.cover, - ), - ) - : Reaction( - value: '', - icon: Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: 24, - fit: BoxFit.cover, - ), - ), - likePopupWidget: selectedReaction != null - ? Image.network( - selectedReaction.image, - width: 24, - height: 24, - fit: BoxFit.cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: 24, - fit: BoxFit.cover, - ), + commonObj: commonobjmodel!.data[index], + forWhichTab: 'popular', + reactions: _reactions, + selectedReactions: _selectedReactions, + currentIndex: index, ), - // normalcardtile2( - // profileImg: popularTabData[index]["profileImg"], - // title: popularTabData[index]["title"], - // mainImg: popularTabData[index]["mainImg"], - // containerTitle: popularTabData[index]["containerTitle"], - // description: 'test', - // create_at: '1 hour', - // total_comments: '20', - // total_likes: '20', - // total_save: '10', - // community_name: 'text', - // postId: '', - // ), sizedBoxHeight(20.h) ], ); @@ -2882,37 +1287,20 @@ class LatestTab extends StatefulWidget { } class _LatestTabState extends State { - // late Future latestfuture; FutureGroup futureGroup = FutureGroup(); @override void initState() { - futureGroup.add(LatespostApi().getLatestPostApi().then((value) { - _initializeData(); - })); - // futureGroup.add( - // ); - // latestfuture = LatespostApi().getLatestPostApi(); + futureGroup.add(LatespostApi().getLatestPostApi()); futureGroup.close(); super.initState(); } List _reactions = []; Map _selectedReactions = {}; + final CountersHelper countersHelper = Get.find(); - Future _initializeData() async { - await _fetchIcons(); - // _initializeSelectedReaction(); - for (var post in latestpostobj!.data) { - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; // This is safe now - } else { - likeIconIdnew = 0; // Or handle it as needed - } - _initializeSelectedReaction(post.id!); // Pass the post ID - } - } - + int? likeIconIdnew; Future _fetchIcons() async { var response = await Communityallgetmethod().getLikeicons(); if (response.status == ResponseStatus.SUCCESS) { @@ -2920,128 +1308,106 @@ class _LatestTabState extends State { FetchlikeIconsModel fetchlikeIconsModel = FetchlikeIconsModel.fromJson(responseData); - setState(() { - _reactions = fetchlikeIconsModel.data - ?.map((data) => ReactionData( - id: data.id!, - image: data.image!, - )) - .toList() ?? - []; - for (var post in latestpostobj!.data) { - _initializeSelectedReaction(post.id!); + _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, + ); + + _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'); } - }); - } - } - - int? likeIconIdnew; - - void _initializeSelectedReaction(int postId) { - // Check if there's a stored likeIconId for this post - if (likeIconIdnew != null && likeIconIdnew != 0 && _reactions.isNotEmpty) { - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - setState(() { - _selectedReactions[postId] = - selectedReaction; // Set selected reaction for this post - print( - 'Selected reaction for post $postId is ${_selectedReactions[postId].toString()}'); - log(_selectedReactions[postId].toString()); - }); - } else { - setState(() { - _selectedReactions[postId] = null; // No reaction selected - print('No reaction selected for post $postId'); - }); - } - } - - Future _handleReactionChange(ReactionData? reaction, int postId) async { - // Check if the postId is valid - if (postId == null) return; - - setState(() { - if (reaction == null) { - _selectedReactions[postId] = - null; // Mark reaction as removed for this post - } else { - _selectedReactions[postId] = - reaction; // Set the selected reaction for this post } - }); - - try { - await LikeUploaddata( - reaction?.id, - postId, - ); - } catch (error) { - print('Error updating reaction: $error'); - setState(() { - _selectedReactions[postId] = - reaction; // Restore previous reaction if needed - }); + setState(() {}); } } - LikeUploaddata(int? likeIconId, int? postid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": postid, - "like_icons_xid": likeIconId ?? '', - }; - final data = await CommunitypostMethod().postLikepost(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - print("like done"); - return utils.showToast(data.message); - } else { - // Get.back(); - print("like not done"); - return utils.showToast(data.message); + bool _isDataInitialized = true; + + Future setValues() async { + if (_isDataInitialized) { + _setModel(); + countersHelper.setListsPopular(); + await _fetchIcons(); + + _isDataInitialized = false; } } - saveunsavepost(int latestpostid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": latestpostid, - }; - final data = await Communitypostmethod().postUserSave(updata); - if (data.status == ResponseStatus.SUCCESS) { - LatespostApi().getLatestPostApi().then((value) { - _initializeData(); - setState(() {}); - }); + _sortTags(index) { + var tags = commonobjmodel!.data[index].attachTags + .where((tag) => tag.manageTag?.name?.isNotEmpty ?? false) + .map((tag) => tag.manageTag!) + .toList(); - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } + return tags; } - pinunpinUser(int userid) async { - // utils.loader(); - Map updata = { - "pin_iam_principal_xid": userid, - }; - final data = await SidebarTags().postUserpin(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - LatespostApi().getLatestPostApi().then((value) { - _initializeData(); - setState(() {}); - }); - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } + _setModel() { + commonobjmodel = null; + commonobjmodel = CommonDatumObjModel( + status: latestpostobj!.status, + statusCode: latestpostobj!.statusCode, + message: latestpostobj!.message, + data: latestpostobj!.data + .map((e) => CommonDatumObjModelData( + id: e.id, + likecount: e.likecount, + isISaved: e.isISaved, + tagsXid: e.tagsXid, + isILiked: e.isILiked, + totalComment: e.totalComment, + totalSave: e.totalSave, + iamPrincipalXid: e.iamPrincipalXid, + postIn: e.postIn, + caption: e.caption, + image: e.image, + manageTagsXids: e.manageTagsXids, + postAs: e.postAs, + ctaTitle: e.ctaTitle, + ctaLink: e.ctaLink, + createdAt: e.createdAt, + likeIcon: LikeIcon1( + likeIcon: LikeIconClass1( + id: e.likeIcon?.likeIcon?.id, + image: e.likeIcon?.likeIcon?.image), + likeIconsXid: e.likeIcon?.likeIconsXid, + ), + totalViewCount: e.totalViewCount, + totalReactionCount: e.totalReactionCount, + totalCommentCount: e.totalCommentCount, + totalImpressionCount: e.totalImpressionCount, + totalPopularScore: e.totalPopularScore, + totalHoursAgo: e.totalHoursAgo, + iamPrincipal: IamPrincipal( + id: e.iamPrincipal!.id, + isUserPinned: e.iamPrincipal!.isUserPinned, + principalTypeXid: e.iamPrincipal!.principalTypeXid, + userName: e.iamPrincipal!.userName, + fullName: e.iamPrincipal!.fullName, + profilePhoto: e.iamPrincipal!.profilePhoto), + community: Community( + id: e.community!.id, + communityProfilePhoto: e.community!.communityProfilePhoto, + communityName: e.community!.communityName), + attachTags: e.attachTags + .map((e) => AttachTag1( + managePostXid: e.managePostXid, + manageTagXid: e.manageTagXid, + manageTag: ManageTagPopular( + id: e.manageTag?.id, + isPinned: e.manageTag?.isPinned, + name: e.manageTag?.name))) + .toList())) + .toList()); } @override @@ -3070,8 +1436,7 @@ class _LatestTabState extends State { if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) { - print("Data fetched-->"); - + setValues(); return Stack( clipBehavior: Clip.none, children: [ @@ -3091,7 +1456,7 @@ class _LatestTabState extends State { child: Column( children: [ Text( - "No Data Found", + "No Post Available", style: TextStyle( color: Colors.white, fontSize: 16.sp, @@ -3105,1442 +1470,31 @@ class _LatestTabState extends State { ) : Column( children: [ - sizedBoxHeight(16.h), + sizedBoxHeight(20.h), Expanded( child: ListView.builder( shrinkWrap: true, - itemCount: latestpostobj!.data.length, + itemCount: commonobjmodel!.data.length, itemBuilder: (context, index) { var timeAgo = ConvertServerDateToUserDate() .convertServerDateToReadableFormate( - latestpostobj!.data[index].createdAt + commonobjmodel!.data[index].createdAt .toString()); - var postId = latestpostobj!.data[index].id; - var selectedReaction = _selectedReactions[postId]; - if (index == 1) { - return - // announcecardtile( - // profileImg: latestpostobj! - // .data[index].iamPrincipal!.profilePhoto ?? - // '', - // title: latestpostobj! - // .data[index].iamPrincipal!.fullName ?? - // '', - // mainImg: latestpostobj!.data[index].image ?? '', - // containerTitle: - // latestpostobj!.data[index].tagNames ?? [''], - // create_at: timeAgo, - // community_name: latestpostobj! - // .data[index].community!.communityName ?? - // '', - // totalcomments: latestpostobj! - // .data[index].totalComment - // .toString(), - // description: - // latestpostobj!.data[index].caption ?? '', - // totalSave: - // latestpostobj!.data[index].totalSave.toString(), - // ); - Column( - children: [ - commonGlassUIBlue( - width: double.infinity, - height: 840.h, - borderRadius: BorderRadius.circular(1), - customWidget: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - sizedBoxHeight(25.h), - Padding( - padding: - EdgeInsets.only(left: 16.w), - child: text16w700_FCFCFC( - "#Announcement"), - ), - sizedBoxHeight(25.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - CircleAvatar( - foregroundImage: NetworkImage( - latestpostobj! - .data[index] - .iamPrincipal! - .profilePhoto ?? - ''), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - text16w400_FCFCFC( - latestpostobj! - .data[index] - .iamPrincipal! - .fullName ?? - ''), - sizedBoxHeight(5.h), - Row( - children: [ - Image.asset( - 'assets/images/png/community 1 (traced).png', - height: 14.w, - width: 14.w, - ), - sizedBoxWidth(7.w), - text12w400_FCFCFC( - latestpostobj! - .data[index] - .community! - .communityName ?? - '', - ), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color( - 0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC( - timeAgo), - ], - ) - ], - ), - const Spacer(), - PopupMenuButton( - surfaceTintColor: - const Color(0xFF222935), - constraints: - BoxConstraints.tightFor( - width: 176.w), - offset: const Offset(0, 50), - color: - const Color(0xFF222935), - tooltip: "", - itemBuilder: (BuildContext - context) => - [ - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Report Post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/Vector (5).png", - height: 15.h, - width: 15.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Share post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/share.png", - height: 20.h, - width: 20.w, - ) - ], - ), - ), - ), - // const PopupMenuDivider(), - // PopupMenuItem( - // onTap: () {}, - // child: Padding( - // padding: - // EdgeInsets.symmetric( - // horizontal: 12.w), - // child: Row( - // children: [ - // Text( - // 'Pin', - // style: TextStyle( - // fontSize: 16.sp, - // color: Colors.white, - // fontWeight: - // FontWeight.w800, - // fontFamily: - // "Nunito Sans", - // ), - // ), - // const Spacer(), - // Image.asset( - // "assets/images/png/f7_pin-fill (2).png", - // height: 25.h, - // width: 25.w, - // ) - // ], - // ), - // ), - // ), - ], - child: Image.asset( - 'assets/images/png/Group 1000004071.png', - width: 16.w, - height: 18.h, - ), - ), - sizedBoxWidth(5.w) - ], - ), - ), - sizedBoxHeight(20.h), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName.postdetailsScreen, - arguments: { - "PostId": latestpostobj! - .data[index].id - .toString() - }); - }, - child: Container( - height: 390.h, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - latestpostobj! - .data[index] - .image ?? - ''))), - ), - ), - sizedBoxHeight(20.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Column(children: [ - SizedBox( - height: 30.h, - width: double.infinity, - child: ListView.builder( - scrollDirection: - Axis.horizontal, - shrinkWrap: true, - // Filter the tags to include only those with a non-null and non-empty name - itemCount: latestpostobj! - .data[index].attachTags - .where((tag) => - tag.manageTag?.name - ?.isNotEmpty ?? - false) - .length, - itemBuilder: - (context, tagIndex) { - // Filtered list of tags - var filteredTags = - latestpostobj! - .data[index] - .attachTags - .where((tag) => - tag - .manageTag - ?.name - ?.isNotEmpty ?? - false) - .toList(); - - // Safely get the manageTag object - var manageTag = - filteredTags[tagIndex] - .manageTag; - - // Get the tag name, ensuring it's not null or empty - String tagName = - manageTag?.name ?? ''; - - return Padding( - padding: - EdgeInsets.only( - right: 12.w, - left: 12.w), - child: GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .tagdetailscreen, - arguments: { - 'tagid': - // filteredTags[ - // tagIndex] - // .manageTagXid, - latestpostobj! - .data[ - index] - .attachTags[ - tagIndex] - .manageTag! - .id, - 'tagname': - tagName, - 'ispinnedtag': filteredTags[ - tagIndex] - .manageTag! - .isPinned - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .start, - children: [ - commonContainer( - width: 130.w, - height: 30.h, - borderRadius: - BorderRadius - .circular( - 30.r), - borderColor: - const Color( - 0xFFD90B2E), - opacity1: 0.04, - opacity2: 0.05, - customWidget: - Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 10.w), - child: Center( - child: text14w400_FCFCFC( - '#${tagName}'), - ), - ), - ), - ], - ), - ), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - height: 60.h, - width: double.infinity, - child: SingleChildScrollView( - child: text16w400_FCFCFC( - latestpostobj! - .data[index] - .caption ?? - ''), - ), - ), - sizedBoxHeight(20.h), - Row(children: [ - InkWell( - onTap: () {}, - child: stackReaction( - number: latestpostobj! - .data[index] - .likecount - .toString(), - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), - ), - const Spacer(), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 13.h, - width: 13.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - latestpostobj!.data[index] - .totalComment - .toString()), - sizedBoxWidth(20.w), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Vector (1).png', - height: 12.h, - width: 12.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - latestpostobj! - .data[index].totalSave - .toString()), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceAround, - children: [ - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Column( - children: [ - ReactionButton< - String>( - onReactionChanged: - (reaction) async { - if (selectedReaction != - null && - reaction?.value == - selectedReaction - .id - .toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange( - selectedReaction, - latestpostobj! - .data[ - index] - .id!); - } else { - // User selected a new reaction - var newSelectedReaction = - _reactions - .firstWhere( - (r) => - r.id.toString() == - reaction - ?.value, - orElse: () => - _reactions - .first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, - latestpostobj! - .data[ - index] - .id!); - } - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactions: - _reactions - .map((reaction) => - Reaction< - String>( - value: - reaction.id.toString(), - previewIcon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - icon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - )) - .toList(), - selectedReaction: - selectedReaction != - null - ? Reaction< - String>( - value: selectedReaction - .id - .toString(), - icon: - Image.network( - selectedReaction.image, - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ) - : Reaction< - String>( - value: - '', - icon: - Image.asset( - 'assets/images/png/uiw_like-o.png', - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ), - boxColor: - Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: - const Size( - 30, 30), - boxPadding: - const EdgeInsets - .all(8), - boxAnimationDuration: - const Duration( - milliseconds: - 200), - itemAnimationDuration: - const Duration( - milliseconds: - 500), - hoverDuration: - const Duration( - milliseconds: - 700), - child: selectedReaction != - null - ? Image - .network( - selectedReaction - .image, - width: 24, - height: - 24, - fit: BoxFit - .cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: - 24, - fit: BoxFit - .cover, - ), - ), - sizedBoxHeight(2.h), - text11w400_FCFCFC( - 'Like'), - ], - ) - ], - ), - GestureDetector( - onTap: () {}, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Comment') - ], - ), - ), - Column( - children: [ - GestureDetector( - onTap: () async { - int latestpostid = - latestpostobj! - .data[index] - .id!; - await saveunsavepost( - latestpostid); - }, - child: latestpostobj! - .data[ - index] - .isISaved == - true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: 19.h, - width: 19.w, - ), - ), - // Image.asset( - // 'assets/images/png/Frame 1000004089.png', - // height: 19.h, - // width: 19.w, - // ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Save') - ], - ) - ], - ), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - ]), - ), - ], - )), - sizedBoxHeight(20.h), - ], - ); - } else { - return Column( - children: [ - // normalcardtile2( - // profileImg: latestpostobj!.data[index] - // .iamPrincipal!.profilePhoto ?? - // '', - // title: latestpostobj! - // .data[index].iamPrincipal!.fullName ?? - // '', - // mainImg: latestpostobj!.data[index].image ?? '', - // containerTitle: - // latestpostobj!.data[index].tagNames ?? [''], - // description: - // latestpostobj!.data[index].caption ?? '', - // create_at: timeAgo, - // total_comments: latestpostobj! - // .data[index].totalComment - // .toString(), - // total_likes: latestpostobj! - // .data[index].likecount - // .toString(), - // total_save: latestpostobj!.data[index].totalSave - // .toString(), - // community_name: latestpostobj! - // .data[index].community!.communityName - // .toString(), - // ), - commonGlassUI( - width: double.infinity, - height: 765.h, - mainOpacity: 1, - borderRadius: BorderRadius.circular(1), - customWidget: Column( - children: [ - sizedBoxHeight(25.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - CircleAvatar( - foregroundImage: NetworkImage( - latestpostobj! - .data[index] - .iamPrincipal! - .profilePhoto ?? - ''), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - text16w400_FCFCFC( - latestpostobj! - .data[index] - .iamPrincipal! - .fullName ?? - ''), - sizedBoxHeight(5.h), - Row( - children: [ - Image.asset( - 'assets/images/png/community 1 (traced).png', - height: 14.w, - width: 14.w, - ), - sizedBoxWidth(7.w), - text12w400_FCFCFC( - latestpostobj! - .data[index] - .community! - .communityName - .toString()), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color( - 0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC( - timeAgo!), - ], - ) - ], - ), - const Spacer(), - PopupMenuButton( - surfaceTintColor: - const Color(0xFF222935), - constraints: - BoxConstraints.tightFor( - width: 176.w), - offset: const Offset(0, 50), - color: - const Color(0xFF222935), - tooltip: "", - itemBuilder: (BuildContext - context) => - [ - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Report Post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/Vector (5).png", - height: 15.h, - width: 15.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - 'Share post', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/share.png", - height: 20.h, - width: 20.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () async { - int pinPospostid = - latestpostobj! - .data[index] - .iamPrincipal! - .id!; - await pinunpinUser( - pinPospostid); - }, - child: Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 12.w), - child: Row( - children: [ - Text( - latestpostobj! - .data[index] - .iamPrincipal! - .isUserPinned == - true - ? 'Unpin' - : 'Pin', - style: - TextStyle( - fontSize: - 16.sp, - color: Colors - .white, - fontWeight: - FontWeight - .w800, - fontFamily: - "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 25.h, - width: 25.w, - ) - ], - ), - ), - ), - ], - child: Image.asset( - 'assets/images/png/Group 1000004071.png', - width: 16.w, - height: 18.h, - ), - ), - sizedBoxWidth(5.w) - ], - ), - ), - sizedBoxHeight(20.h), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName.postdetailsScreen, - arguments: { - "PostId": latestpostobj! - .data[index].id - .toString() - }); - }, - child: Container( - height: 360, - width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.cover, - image: NetworkImage( - latestpostobj!.data[index] - .image ?? - '', - ), - ), - ), - ), - ), - sizedBoxHeight(20.h), - Padding( - padding: EdgeInsets.symmetric( - horizontal: 16.w), - child: Column(children: [ - // SizedBox( - // height: 30.h, - // child: ListView.builder( - // scrollDirection: Axis.horizontal, - // shrinkWrap: true, - // itemCount: latestpostobj! - // .data[index].attachTags.length, - // itemBuilder: (context, tagIndex) { - // print( - // 'tags id are ${latestpostobj!.data[index].attachTags[tagIndex].manageTag!.id}'); - // print( - // 'tags name are ${latestpostobj!.data[index].attachTags[tagIndex].manageTag!.name}'); - // return Padding( - // padding: EdgeInsets.only( - // right: 12.w), - // child: GestureDetector( - // onTap: () { - // Get.toNamed( - // RouteName - // .tagdetailscreen, - // arguments: { - // 'tagid': - // latestpostobj! - // .data[ - // index] - // .attachTags[ - // tagIndex].manageTag! - // .id, - // 'tagname': - // latestpostobj! - // .data[ - // index] - // .attachTags[ - // tagIndex].manageTag! - // .name, - // }); - // }, - // child: Row( - // mainAxisAlignment: - // MainAxisAlignment - // .start, - // children: [ - // // containertile2( - // // text: latestpostobj! - // // .data[index] - // // .tagsData[ - // // tagIndex] - // // .name!), - // commonContainer( - // width: 130.w, - // height: 30.h, - // borderRadius: - // BorderRadius - // .circular( - // 30.r), - // borderColor: - // const Color( - // 0xFFD90B2E), - // opacity1: 0.04, - // opacity2: 0.05, - // customWidget: - // Padding( - // padding: EdgeInsets - // .symmetric( - // horizontal: - // 10.w), - // child: Center( - // child: text14w400_FCFCFC(latestpostobj! - // .data[ - // index] - // .attachTags[ - // tagIndex].manageTag! - // .name!)), - // )), - // ], - // )), - // ); - // }, - // ), - // ), - SizedBox( - height: 30.h, - width: double.infinity, - child: ListView.builder( - scrollDirection: - Axis.horizontal, - shrinkWrap: true, - // Filter the tags to include only those with a non-null and non-empty name - itemCount: latestpostobj! - .data[index].attachTags - .where((tag) => - tag.manageTag?.name - ?.isNotEmpty ?? - false) - .length, - itemBuilder: - (context, tagIndex) { - // Filtered list of tags - var filteredTags = - latestpostobj! - .data[index] - .attachTags - .where((tag) => - tag - .manageTag - ?.name - ?.isNotEmpty ?? - false) - .toList(); - - // Safely get the manageTag object - var manageTag = - filteredTags[tagIndex] - .manageTag; - - // Get the tag name, ensuring it's not null or empty - String tagName = - manageTag?.name ?? ''; - - return Padding( - padding: - EdgeInsets.only( - right: 12.w, - left: 12.w), - child: GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .tagdetailscreen, - arguments: { - 'tagid': latestpostobj! - .data[ - index] - .attachTags[ - tagIndex] - .manageTag! - .id, - 'tagname': - tagName, - 'ispinnedtag': filteredTags[ - tagIndex] - .manageTag! - .isPinned - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .start, - children: [ - commonContainer( - width: 130.w, - height: 30.h, - borderRadius: - BorderRadius - .circular( - 30.r), - borderColor: - const Color( - 0xFFD90B2E), - opacity1: 0.04, - opacity2: 0.05, - customWidget: - Padding( - padding: EdgeInsets - .symmetric( - horizontal: - 10.w), - child: Center( - child: text14w400_FCFCFC( - '#${tagName}'), - ), - ), - ), - ], - ), - ), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - height: 80.h, - width: double.infinity, - child: SingleChildScrollView( - child: text16w400_FCFCFC( - latestpostobj! - .data[index] - .caption ?? - ''), - ), - ), - sizedBoxHeight(20.h), - Row(children: [ - InkWell( - onTap: () { - Get.toNamed( - RouteName - .reactionview, - arguments: { - 'postId': postId - .toString(), - }); - }, - child: stackReaction( - number: latestpostobj! - .data[index] - .likecount - .toString(), - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), - ), - const Spacer(), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 13.h, - width: 13.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - latestpostobj!.data[index] - .totalComment - .toString()), - sizedBoxWidth(20.w), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: - const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Vector (1).png', - height: 12.h, - width: 12.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC( - latestpostobj! - .data[index].totalSave - .toString()), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceAround, - children: [ - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Column( - children: [ - ReactionButton< - String>( - onReactionChanged: - (reaction) async { - if (selectedReaction != - null && - reaction?.value == - selectedReaction - .id - .toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange( - selectedReaction, - latestpostobj! - .data[ - index] - .id!); - } else { - // User selected a new reaction - var newSelectedReaction = - _reactions - .firstWhere( - (r) => - r.id.toString() == - reaction - ?.value, - orElse: () => - _reactions - .first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, - latestpostobj! - .data[ - index] - .id!); - } - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactions: - _reactions - .map((reaction) => - Reaction< - String>( - value: - reaction.id.toString(), - previewIcon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - icon: Image.network(reaction.image, - width: 24, - height: 24, - fit: BoxFit.cover), - )) - .toList(), - selectedReaction: - selectedReaction != - null - ? Reaction< - String>( - value: selectedReaction - .id - .toString(), - icon: - Image.network( - selectedReaction.image, - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ) - : Reaction< - String>( - value: - '', - icon: - Image.asset( - 'assets/images/png/uiw_like-o.png', - width: - 24, - height: - 24, - fit: - BoxFit.cover, - ), - ), - boxColor: - Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: - const Size( - 30, 30), - boxPadding: - const EdgeInsets - .all(8), - boxAnimationDuration: - const Duration( - milliseconds: - 200), - itemAnimationDuration: - const Duration( - milliseconds: - 500), - hoverDuration: - const Duration( - milliseconds: - 700), - child: selectedReaction != - null - ? Image - .network( - selectedReaction - .image, - width: 24, - height: - 24, - fit: BoxFit - .cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: - 24, - fit: BoxFit - .cover, - ), - ), - sizedBoxHeight(2.h), - text11w400_FCFCFC( - 'Like'), - ], - ) - ], - ), - GestureDetector( - onTap: () { - Get.toNamed( - RouteName - .postdetailsScreen, - arguments: { - "PostId": - latestpostobj! - .data[ - index] - .id - .toString() - }); - }, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Comment') - ], - ), - ), - InkWell( - onTap: () {}, - child: Column( - children: [ - GestureDetector( - onTap: () async { - int latestpostid = - latestpostobj! - .data[ - index] - .id!; - await saveunsavepost( - latestpostid); - }, - child: latestpostobj! - .data[ - index] - .isISaved == - true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: - 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: - 19.h, - width: 19.w, - ), - ), - // Image.asset( - // 'assets/images/png/Frame 1000004089.png', - // height: 19.h, - // width: 19.w, - // ), - sizedBoxHeight(8.h), - text11w400_FCFCFC( - 'Save') - ], - ), - ), - ], - ), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - ]), - ), - ], - )), - sizedBoxHeight(20.h) - ], - ); - } + return Column( + children: [ + NormalCardTile( + tags: _sortTags(index), + create_at: timeAgo ?? '1 hour', + commonObj: commonobjmodel!.data[index], + forWhichTab: 'latest', + reactions: _reactions, + selectedReactions: _selectedReactions, + currentIndex: index, + ), + sizedBoxHeight(20.h) + ], + ); }, ), ), diff --git a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart index 210dc05..c6115b2 100644 --- a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart +++ b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart @@ -6,34 +6,25 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; -import 'package:flutter_reaction_button/flutter_reaction_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:get/get_state_manager/get_state_manager.dart'; -import 'package:regroup/Common/CommonGlassmorphism.dart'; -import 'package:regroup/Common/CommonWidget.dart'; -import 'package:regroup/Common/ConvertServerDateToUserDate.dart'; + import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Global.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/fetchicons.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/LatestPost.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/PopularPost.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/getmethod.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/postmethod.dart'; -import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/Model/PostDetailModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/CommonDatumObjModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; +import 'package:regroup/Main_Screens/Community_HomePage/Community.dart'; import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/ViewModel/CommentsHelper.dart'; import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/ViewModel/CommentsRepository.dart'; import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/ViewModel/PostDetailApi.dart'; -import 'package:regroup/Main_Screens/Community_HomePage/view_model/communitypostmethod.dart'; import 'package:regroup/Main_Screens/ProfileTab/view_model/profilePostmethod.dart'; import 'package:regroup/Utils/Common/CommonAppbar.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:async/async.dart'; -import 'package:regroup/sidemenu/view_model/postmethod.dart'; class PostDetailsScreen extends StatefulWidget { const PostDetailsScreen({super.key}); @@ -43,160 +34,6 @@ class PostDetailsScreen extends StatefulWidget { } class _PostDetailsScreenState extends State { - List _reactions = []; - Map _selectedReactions = {}; - bool isOnceForPost = true; - - Future _initializeData() async { - if (isOnceForPost) { - await _fetchIcons(); - // _initializeSelectedReaction(); - if (postDetailObj?.data?.likeIcon != null) { - likeIconIdnew = postDetailObj?.data?.likeIcon!.likeIconsXid; - } else { - likeIconIdnew = 0; // Or handle it as needed - } - _initializeSelectedReaction(postDetailObj!.data!.id!); // Pass the post ID - - isOnceForPost = false; - } - } - - Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); - - setState(() { - _reactions = fetchlikeIconsModel.data - ?.map((data) => ReactionData( - id: data.id!, - image: data.image!, - )) - .toList() ?? - []; - _initializeSelectedReaction(postDetailObj!.data!.id!); - }); - } - } - - int? likeIconIdnew; - - void _initializeSelectedReaction(int postId) { - // Check if there's a stored likeIconId for this post - if (likeIconIdnew != null && likeIconIdnew != 0 && _reactions.isNotEmpty) { - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - setState(() { - _selectedReactions[postId] = - selectedReaction; // Set selected reaction for this post - print( - 'Selected reaction for post $postId is ${_selectedReactions[postId].toString()}'); - log(_selectedReactions[postId].toString()); - }); - } else { - setState(() { - _selectedReactions[postId] = null; // No reaction selected - print('No reaction selected for post $postId'); - }); - } - } - - Future _handleReactionChange(ReactionData? reaction, int postId) async { - // Check if the postId is valid - if (postId == null) return; - - setState(() { - if (reaction == null) { - _selectedReactions[postId] = - null; // Mark reaction as removed for this post - } else { - _selectedReactions[postId] = - reaction; // Set the selected reaction for this post - } - }); - - try { - await LikeUploaddata( - reaction?.id, - postId, - ); - } catch (error) { - print('Error updating reaction: $error'); - setState(() { - _selectedReactions[postId] = - reaction; // Restore previous reaction if needed - }); - } - } - - LikeUploaddata(int? likeIconId, int? postid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": postid, - "like_icons_xid": likeIconId ?? '', - }; - final data = await CommunitypostMethod().postLikepost(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - print("like done"); - return utils.showToast(data.message); - } else { - // Get.back(); - print("like not done"); - return utils.showToast(data.message); - } - } - -//savePost - - saveunsavepost(int postid) async { - // utils.loader(); - Map updata = { - "manage_posts_xid": postid, - }; - final data = await Communitypostmethod().postUserSave(updata); - if (data.status == ResponseStatus.SUCCESS) { - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); - - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } - } - -//PinUser - - pinunpinUser(int userid) async { - // utils.loader(); - Map updata = { - "pin_iam_principal_xid": userid, - }; - final data = await SidebarTags().postUserpin(updata); - if (data.status == ResponseStatus.SUCCESS) { - // Get.back(); - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); - return utils.showToast(data.message); - } else { - // Get.back(); - return utils.showToast(data.message); - } - } - - //followunfollow - int? followunfollowid; FollowUnfollowUploadata() async { @@ -206,10 +43,7 @@ class _PostDetailsScreenState extends State { }; final data = await Profilepostmethod().postunfollowuser(newupdata); if (data.status == ResponseStatus.SUCCESS) { - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); + PostDetailApi().getPostDetail(mainpostid).then((value) {}); } else { Get.back(); return utils.showToast(data.message); @@ -223,14 +57,27 @@ class _PostDetailsScreenState extends State { final CommentsHelper _commentsHelper = Get.put(CommentsHelper()); String? mainpostid; + List? tags; + String? create_at; + CommonDatumObjModelData? commonObj; + String? formWhichTab; + List? reactions; + Map? selectedReactions; + int? currentIndex; @override void initState() { - // var postId = Get.arguments['PostId'] ?? ''; - mainpostid = Get.arguments['PostId'] ?? ''; + mainpostid = Get.arguments['postId'].toString(); + tags = Get.arguments['tagsList']; + create_at = Get.arguments['created_at']; + commonObj = Get.arguments['commonObj']; + formWhichTab = Get.arguments['fromWhichTab']; + reactions = Get.arguments['reactions']; + selectedReactions = Get.arguments['selectedReactions']; + currentIndex = Get.arguments['currentIndex']; + futureGroup.add(CommentsRepository().getAllComments(mainpostid)); futureGroup.add(PostDetailApi().getPostDetail(mainpostid)); - futureGroup.close(); super.initState(); } @@ -267,10 +114,6 @@ class _PostDetailsScreenState extends State { _commentsHelper.isLoading.value = false; _controllerComments.clear(); })); - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); } } @@ -290,10 +133,6 @@ class _PostDetailsScreenState extends State { _commentsHelper.isLoading.value = false; _controllerComments.clear(); })); - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); } } // _setComments(index) { @@ -321,10 +160,6 @@ class _PostDetailsScreenState extends State { .then((value) => setState(() { isOnce = true; })); - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); } } @@ -337,10 +172,6 @@ class _PostDetailsScreenState extends State { .then((value) => setState(() { isOnce = true; })); - PostDetailApi().getPostDetail(mainpostid).then((value) { - _initializeData(); - setState(() {}); - }); } } @@ -349,52 +180,50 @@ class _PostDetailsScreenState extends State { @override Widget build(BuildContext context) { return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) { - return Scaffold( - resizeToAvoidBottomInset: false, - backgroundColor: const Color(0xFF222935), - extendBody: true, - appBar: const CommonAppbar( - titleTxt: "Post", - ), - body: FutureBuilder( - future: futureGroup.future, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); - } else if (snapshot.hasError) { - return Center( - child: Text( - '${snapshot.error} occurred', - style: TextStyle(fontSize: 18.spMin), - ), - ); - } else if (snapshot.connectionState == ConnectionState.done) { - _setViewMoreList(); - _initializeData(); - return _buildBody(isKeyboardVisible); - } else { - return const Center(child: Text('Something went wrong')); - } - }, - )); + return WillPopScope( + onWillPop: () async { + Get.back(result: true); + return false; // Prevent default back button action + }, + child: Scaffold( + resizeToAvoidBottomInset: false, + backgroundColor: const Color(0xFF222935), + extendBody: true, + appBar: const CommonAppbar( + customBack: true, + // customRouteName: RouteName.communityScreen, + titleTxt: "Post", + ), + body: FutureBuilder( + future: futureGroup.future, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator( + color: Colors.blue, + ), + ); + } else if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } else if (snapshot.connectionState == ConnectionState.done) { + _setViewMoreList(); + + return _buildBody(isKeyboardVisible); + } else { + return const Center(child: Text('Something went wrong')); + } + }, + )), + ); }); } _buildBody(isKeyboardVisible) { - var postDetailData = postDetailObj!.data!; - var postId = postDetailData.id; - var selectedReaction = _selectedReactions[postId]; - var timeAgo = ConvertServerDateToUserDate() - .convertServerDateToReadableFormate( - postDetailData.createdAt.toString()); - var tags = postDetailData.attachTags - .where((tag) => tag.manageTag?.name?.isNotEmpty ?? false) - .map((tag) => tag.manageTag!) - .toList(); return Stack(children: [ Container( decoration: const BoxDecoration( @@ -405,112 +234,17 @@ class _PostDetailsScreenState extends State { SingleChildScrollView( child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - PostCardTile( - profileImg: postDetailData.iamPrincipal!.profilePhoto ?? '', - title: postDetailData.iamPrincipal!.fullName ?? "", - mainImg: postDetailData.image ?? "", - tags: tags, - description: postDetailData.caption ?? 'test', - createAt: timeAgo ?? '1 hour', - totalComments: postDetailData.totalCommentCount.toString() ?? '20', - totalLikes: postDetailData.totalReactionCount.toString(), - totalSave: postDetailData.totalSave.toString() ?? '10', - communityName: postDetailData.community!.communityName ?? 'text', - postId: postDetailData.id.toString(), - UserId: postDetailData.iamPrincipalXid, - mainImagetap: () { - // Get.toNamed(RouteName.postdetailsScreen, - // arguments: { - // "PopularPostId": - // popularData.id.toString() - // }); - }, - onSaveIconTap: () async { - await saveunsavepost(postDetailData.id!); - }, - isISaved: postDetailData.isISaved, - PinPopupTap: () async { - int pinPospostid = postDetailData.iamPrincipal!.id!; - await pinunpinUser(pinPospostid); - }, - isUserPinned: postDetailData.iamPrincipal!.isUserPinned, - followTap: () { - followunfollowid = postDetailData.iamPrincipalXid; - FollowUnfollowUploadata(); - }, - isIamFollowing: postDetailData.isIFollow, - onReactionChangedLike: (reaction) async { - if (selectedReaction != null && - reaction?.value == selectedReaction.id.toString()) { - // User tapped on the currently selected reaction, so remove it - await _handleReactionChange(selectedReaction, postDetailData.id!); - } else { - // User selected a new reaction - var newSelectedReaction = _reactions.firstWhere( - (r) => r.id.toString() == reaction?.value, - orElse: () => _reactions.first, // Default reaction if not found - ); - await _handleReactionChange( - newSelectedReaction, postDetailData.id!); - } - debugPrint('Selected value: ${reaction?.value}'); - }, - reactionsLike: _reactions - .map((reaction) => Reaction( - value: reaction.id.toString(), - previewIcon: Image.network(reaction.image, - width: 24, height: 24, fit: BoxFit.cover), - icon: Image.network(reaction.image, - width: 24, height: 24, fit: BoxFit.cover), - )) - .toList(), - selectedReactionLike: selectedReaction != null - ? Reaction( - value: selectedReaction.id.toString(), - icon: Image.network( - selectedReaction.image, - width: 24, - height: 24, - fit: BoxFit.cover, - ), - ) - : Reaction( - value: '', - icon: Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: 24, - fit: BoxFit.cover, - ), - ), - likePopupWidget: selectedReaction != null - ? Image.network( - selectedReaction.image, - width: 24, - height: 24, - fit: BoxFit.cover, - ) - : Image.asset( - 'assets/images/png/uiw_like-o.png', - width: 24, - height: 24, - fit: BoxFit.cover, - ), + // sizedBoxHeight(35.h), + + NormalCardTile( + tags: tags!, + create_at: create_at!, + commonObj: commonObj!, + forWhichTab: formWhichTab!, + reactions: reactions!, + selectedReactions: selectedReactions!, + currentIndex: currentIndex!, ), - - // PostCardTile( - // profileImg: 'assets/images/png/Ellipse 52.png', - // title: 'Ryan Dorwat', - // mainImg: 'assets/images/png/Rectangle 25.png', - // containerTitle: [ - // 'Football', - // 'Marathon', - // 'Events', - // 'Marathon', - // 'Events' - // ]), - sizedBoxHeight(35.h), - // ListView.builder( // physics: const NeverScrollableScrollPhysics(), // shrinkWrap: true, @@ -693,6 +427,7 @@ class _PostDetailsScreenState extends State { // ); // }, // ), + sizedBoxHeight(35.h), ListView.builder( physics: const NeverScrollableScrollPhysics(), @@ -981,544 +716,3 @@ class _PostDetailsScreenState extends State { ]); } } - -class PostCardTile extends StatefulWidget { - final String profileImg; - final String title; - final String mainImg; - final String description; - final List tags; - final String communityName; - final String totalComments; - final String totalLikes; - final String totalSave; - final String? createAt; - final String? postId; - final int? UserId; - final void Function()? onSaveIconTap; - final void Function()? PinPopupTap; - final void Function()? followTap; - final bool? isIamFollowing; - - final bool? isISaved; - final bool? isUserPinned; - - // final dynamic commonpostobj; - final void Function(Reaction?) onReactionChangedLike; - final List?> reactionsLike; - final Reaction? selectedReactionLike; - final Widget? likePopupWidget; - final void Function()? mainImagetap; - - const PostCardTile( - {Key? key, - required this.profileImg, - required this.title, - required this.mainImg, - required this.description, - // required this.containerTitle, - required this.tags, - required this.communityName, - required this.totalComments, - required this.totalLikes, - required this.totalSave, - // this.commonpostobj, - required this.onReactionChangedLike, - required this.reactionsLike, - required this.selectedReactionLike, - required this.likePopupWidget, - required this.mainImagetap, - required this.isIamFollowing, - required this.followTap, - required this.UserId, - this.createAt, - this.postId, - this.onSaveIconTap, - this.PinPopupTap, - this.isISaved, - this.isUserPinned}) - : super(key: key); - - @override - _PostCardTileState createState() => _PostCardTileState(); -} - -class _PostCardTileState extends State { - RxString mainImage = 'assets/images/png/uiw_like-o.png'.obs; - - void updateImage(String reaction) { - if (reaction == 'like') { - mainImage.value = 'assets/images/png/f7_hand-thumbsup.png'; - } else if (reaction == 'heart') { - mainImage.value = 'assets/images/png/heart 2.png'; - } else if (reaction == 'party') { - mainImage.value = 'assets/images/png/party-popper 2.png'; - } - } - - @override - Widget build(BuildContext context) { - return commonGlassUI( - width: double.infinity, - height: 800.h, - borderwidth: 0, - borderRadius: BorderRadius.circular(0), - customWidget: Column( - children: [ - sizedBoxHeight(25.h), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CircleAvatar( - foregroundImage: NetworkImage(widget.profileImg), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - text16w400_FCFCFC(widget.title), - const Spacer(), - userIdGlobal == widget.UserId.toString() - ? SizedBox() - : GestureDetector( - onTap: widget.followTap, - child: widget.isIamFollowing == false - ? commonGlassUI( - width: 72.w, - height: 26.h, - borderRadius: - BorderRadius.circular(5.r), - borderColor: - const Color(0xFFD90B2E), - customWidget: Center( - child: - text14400white("Follow")), - borderwidth: 1) - : commonGlassUI( - width: 120.w, - height: 26.h, - borderRadius: - BorderRadius.circular(5.r), - borderColor: - const Color(0xFFD90B2E), - customWidget: Center( - child: - text14400white("Unfollow")), - borderwidth: 1), - ), - sizedBoxWidth(6.w), - PopupMenuButton( - surfaceTintColor: const Color(0xFF222935), - constraints: - BoxConstraints.tightFor(width: 176.w), - offset: const Offset(0, 50), - color: const Color(0xFF222935), - tooltip: "", - itemBuilder: (BuildContext context) => - [ - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: - EdgeInsets.symmetric(horizontal: 12.w), - child: Row( - children: [ - Text( - 'Report Post', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/Vector (5).png", - height: 15.h, - width: 15.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: () {}, - child: Padding( - padding: - EdgeInsets.symmetric(horizontal: 12.w), - child: Row( - children: [ - Text( - 'Share post', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/share.png", - height: 20.h, - width: 20.w, - ) - ], - ), - ), - ), - const PopupMenuDivider(), - PopupMenuItem( - onTap: widget.PinPopupTap, - child: Padding( - padding: - EdgeInsets.symmetric(horizontal: 12.w), - child: Row( - children: [ - Text( - widget.isUserPinned == true - ? 'Unpin' - : 'Pin', - style: TextStyle( - fontSize: 16.sp, - color: Colors.white, - fontWeight: FontWeight.w800, - fontFamily: "Nunito Sans", - ), - ), - const Spacer(), - Image.asset( - "assets/images/png/f7_pin-fill (2).png", - height: 25.h, - width: 25.w, - ) - ], - ), - ), - ), - ], - child: Image.asset( - 'assets/images/png/Group 1000004071.png', - width: 16.w, - height: 18.h, - ), - ), - ], - ), - sizedBoxHeight(15.h), - Row( - children: [ - Image.asset( - 'assets/images/png/community 1 (traced).png', - height: 14.w, - width: 14.w, - ), - sizedBoxWidth(7.w), - text12w400_FCFCFC(widget.communityName), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color(0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC(widget.createAt!), - ], - ) - ], - ), - ), - ], - ), - ), - sizedBoxHeight(20.h), - GestureDetector( - onTap: widget.mainImagetap, - child: Container( - height: 360, - width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.cover, - image: NetworkImage( - widget.mainImg, - ), - ), - ), - ), - ), - sizedBoxHeight(20.h), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w), - child: Column(children: [ - SizedBox( - height: 30.h, - width: double.infinity, - child: ListView.builder( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - itemCount: widget.tags.length, - itemBuilder: (context, index) { - var manageTag = widget.tags[index]; - return Padding( - padding: EdgeInsets.only(right: 12.w, left: 12.w), - child: GestureDetector( - onTap: () { - Get.toNamed(RouteName.tagdetailscreen, - arguments: { - 'tagid': manageTag.id, - 'tagname': manageTag.name, - 'ispinnedtag': manageTag.isPinned, - }); - - // var tags = popularData.attachTags - // .where((tag) => - // tag.manageTag?.name?.isNotEmpty ?? false) - // .map((tag) => tag.manageTag!) - // .toList(); - }, - child: - containertile2(text: ('#${manageTag.name}'))), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - height: 100.h, - child: SingleChildScrollView( - child: Align( - alignment: Alignment.centerLeft, - child: text16w400_FCFCFC(widget.description)))), - sizedBoxHeight(20.h), - Row(children: [ - InkWell( - onTap: () { - Get.toNamed(RouteName.reactionview, arguments: { - 'postId': widget.postId, - }); - }, - child: stackReaction( - number: widget.totalLikes, - containerImages: [ - 'assets/images/png/f7_hand-thumbsup.png', - 'assets/images/png/heart 2.png', - 'assets/images/png/party-popper 2.png' - ]), - ), - const Spacer(), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 13.h, - width: 13.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC(widget.totalComments), - sizedBoxWidth(20.w), - commonContainer( - width: 30.w, - height: 30.h, - borderColor: const Color(0xFF434A53), - borderwidth: 0.43, - opacity1: 0.2, - opacity2: 0.2, - boxShape: BoxShape.circle, - customWidget: Center( - child: Image.asset( - 'assets/images/png/Vector (1).png', - height: 12.h, - width: 12.w, - ), - ), - ), - sizedBoxWidth(12.w), - text14w400_FCFCFC(widget.totalSave), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ReactionButton( - onReactionChanged: widget.onReactionChangedLike, - // (reaction) async { - // if (_selectedReactions[postId] != null && - // reaction?.value == - // _selectedReactions[postId]!.id.toString()) { - // // User tapped on the currently selected reaction, so remove it - // await _handleReactionChange( - // _selectedReactions[postId], postId as int); - // } else { - // // User selected a new reaction - // var newSelectedReaction = _reactions.firstWhere( - // (r) => r.id.toString() == reaction?.value, - // orElse: () => _reactions - // .first, // Default reaction if not found - // ); - // await _handleReactionChange( - // newSelectedReaction, postId as int); - // } - // debugPrint('Selected value: ${reaction?.value}'); - // }, - reactions: widget.reactionsLike, - - // _reactions - // .map((reaction) => Reaction( - // value: reaction.id.toString(), - // previewIcon: Image.network(reaction.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover), - // icon: Image.network(reaction.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover), - // )) - // .toList(), - selectedReaction: widget.selectedReactionLike, - - // _selectedReactions[postId] != null - // ? Reaction( - // value: - // _selectedReactions[postId]!.id.toString(), - // icon: Image.network( - // _selectedReactions[postId]!.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), - // ) - // : Reaction( - // value: '', - // icon: Image.asset( - // 'assets/images/png/uiw_like-o.png', - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), - // ), - boxColor: Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: const Size(30, 30), - boxPadding: const EdgeInsets.all(8), - boxAnimationDuration: - const Duration(milliseconds: 200), - itemAnimationDuration: - const Duration(milliseconds: 500), - hoverDuration: const Duration(milliseconds: 700), - child: widget.likePopupWidget, - - // _selectedReactions[postId] != null - // ? Image.network( - // _selectedReactions[postId]!.image, - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ) - // : Image.asset( - // 'assets/images/png/uiw_like-o.png', - // width: 24, - // height: 24, - // fit: BoxFit.cover, - // ), - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Like'), - ], - ), - Column( - children: [ - GestureDetector( - onTap: widget.onSaveIconTap, - child: widget.isISaved == true - ? Image.asset( - 'assets/images/png/postSaved.png', - height: 19.h, - width: 19.w, - ) - : Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: 19.h, - width: 19.w, - ), - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Save') - ], - ), - ], - ), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - ]), - ), - ], - )); - } - - Widget containertile2({required String text}) { - return commonContainer( - width: 130.w, - height: 30.h, - borderRadius: BorderRadius.circular(30.r), - borderColor: const Color(0xFFD90B2E), - opacity1: 0.04, - opacity2: 0.05, - customWidget: Padding( - padding: EdgeInsets.symmetric(horizontal: 10.w), - child: Center(child: text14w400_FCFCFC(text)), - )); - } - - Widget _buildReactionsPreviewIcon(String assetPath) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: Image.asset( - assetPath, - height: 40.h, - width: 40.w, - ), - ); - } - - Widget _buildReactionsIcon(String assetPath) { - return Column( - children: [ - Image.asset( - assetPath, - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Like') - ], - ); - } -} diff --git a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart index 0c6bbdb..af4e1c8 100644 --- a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart +++ b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart @@ -149,7 +149,7 @@ class _AllTabsState extends State { @override void initState() { - postId = Get.arguments['postId']; + postId = Get.arguments['postId'].toString(); alltabfuture = LikePostApi().postLike({'manage_posts_xid': postId}); super.initState(); @@ -226,9 +226,10 @@ class _LikeTabsState extends State { @override void initState() { - postId = Get.arguments['postId']; + postId = Get.arguments['postId'].toString(); - liketabfuture = LikePostApi() .postLike({'manage_posts_xid': postId, 'like_icons_xid': 1}); + liketabfuture = LikePostApi() + .postLike({'manage_posts_xid': postId, 'like_icons_xid': 1}); super.initState(); } @@ -303,9 +304,10 @@ class _FavouriteTabsState extends State { @override void initState() { - postId = Get.arguments['postId']; + postId = Get.arguments['postId'].toString(); - favouritetabfuture = LikePostApi() .postLike({'manage_posts_xid': postId, 'like_icons_xid': 2}); + favouritetabfuture = LikePostApi() + .postLike({'manage_posts_xid': postId, 'like_icons_xid': 2}); super.initState(); } @@ -380,8 +382,9 @@ class _PartyTabsState extends State { @override void initState() { - postId = Get.arguments['postId']; - partytabfuture = LikePostApi().postLike({'manage_posts_xid': postId, 'like_icons_xid': 3}); + postId = Get.arguments['postId'].toString(); + partytabfuture = LikePostApi() + .postLike({'manage_posts_xid': postId, 'like_icons_xid': 3}); super.initState(); } diff --git a/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart b/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart index 73635cb..b384a73 100644 --- a/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart +++ b/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart @@ -9,9 +9,9 @@ import 'package:regroup/Common/CommonTabBar.dart'; import 'package:regroup/Common/CommonWidget.dart'; import 'package:regroup/Common/ConvertServerDateToUserDate.dart'; import 'package:regroup/Common/base_manager.dart'; -import 'package:regroup/Main_Screens/MyCommunity/Model/fetchicons.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/getmethod.dart'; -import 'package:regroup/Main_Screens/MyCommunity/ViewModel/postmethod.dart'; +import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; +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/Community.dart'; import 'package:regroup/Main_Screens/Community_HomePage/view_model/communitygetmethod.dart'; import 'package:regroup/Main_Screens/Community_HomePage/view_model/communitypostmethod.dart'; diff --git a/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart new file mode 100644 index 0000000..a142fcb --- /dev/null +++ b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart @@ -0,0 +1,59 @@ +import 'package:get/get.dart'; +import 'package:regroup/Main_Screens/Community/Model/CommonDatumObjModel.dart'; +import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart'; + +List combinedListGlobal = []; + CommonDatumObjModel? commonobjmodel; +class CountersHelper extends GetxController { + RxList likesCounterPopular = [].obs; + RxList commentsCounterPopular = [].obs; + RxList savePostCounterPopular = [].obs; + RxList saveButtonPopular = [].obs; + RxList pinButtonPopular = [].obs; + + setListsPopular() { + likesCounterPopular.clear(); + commentsCounterPopular.clear(); + savePostCounterPopular.clear(); + saveButtonPopular.clear(); + + for (var i = 0; i < commonobjmodel!.data.length; i++) { + likesCounterPopular.add(commonobjmodel?.data[i].likecount ?? 0); + commentsCounterPopular + .add(commonobjmodel?.data[i].totalCommentCount ?? 0); + savePostCounterPopular.add(commonobjmodel?.data[i].totalSave ?? 0); + saveButtonPopular.add(commonobjmodel?.data[i].isISaved ?? false); + pinButtonPopular + .add(commonobjmodel?.data[i].iamPrincipal?.isUserPinned ?? false); + } + } + + RxList likesCounterFeed = [].obs; + RxList commentsCounterFeed = [].obs; + RxList savePostCounterFeed = [].obs; + + setListsFeed() { + for (var i = 0; i < combinedListGlobal.length; i++) { + likesCounterLatest.add(combinedListGlobal[i].likecount ?? 0); + commentsCounterLatest.add(combinedListGlobal[i].totalCommentCount ?? 0); + savePostCounterLatest.add(combinedListGlobal[i].totalSave ?? 0); + } + } + + RxList likesCounterLatest = [].obs; + RxList commentsCounterLatest = [].obs; + RxList savePostCounterLatest = [].obs; + + setListsLatest() { + for (var i = 0; i < latestpostobj!.data.length; i++) { + likesCounterFeed.add(latestpostobj!.data[i].likecount ?? 0); + commentsCounterFeed.add(latestpostobj!.data[i].totalCommentCount ?? 0); + savePostCounterFeed.add(latestpostobj!.data[i].totalSave ?? 0); + } + } + + + + +} diff --git a/lib/Main_Screens/MyCommunity/Model/fetchicons.dart b/lib/Main_Screens/MyCommunity/Model/fetchicons.dart deleted file mode 100644 index c6e2f48..0000000 --- a/lib/Main_Screens/MyCommunity/Model/fetchicons.dart +++ /dev/null @@ -1,64 +0,0 @@ -class FetchlikeIconsModel { - String? status; - int? statusCode; - String? message; - List? data; - - FetchlikeIconsModel({this.status, this.statusCode, this.message, this.data}); - - FetchlikeIconsModel.fromJson(Map json) { - status = json['status']; - statusCode = json['status_code']; - message = json['message']; - if (json['data'] != null) { - data = []; - json['data'].forEach((v) { - data!.add(new Data.fromJson(v)); - }); - } - } - - Map toJson() { - final Map data = new Map(); - data['status'] = this.status; - data['status_code'] = this.statusCode; - data['message'] = this.message; - if (this.data != null) { - data['data'] = this.data!.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class Data { - int? id; - String? image; - - Data({this.id, this.image}); - - Data.fromJson(Map json) { - id = json['id']; - image = json['image']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['image'] = this.image; - return data; - } -} - -class ReactionData { - final int id; - final String image; - - ReactionData({required this.id, required this.image}); - - factory ReactionData.fromJson(Map json) { - return ReactionData( - id: json['id'], - image: json['image'], - ); - } -} diff --git a/lib/Main_Screens/ProfileTab/EditProfile/View/ProfileTab.dart b/lib/Main_Screens/ProfileTab/EditProfile/View/ProfileTab.dart index 01b7234..21e4f2c 100644 --- a/lib/Main_Screens/ProfileTab/EditProfile/View/ProfileTab.dart +++ b/lib/Main_Screens/ProfileTab/EditProfile/View/ProfileTab.dart @@ -973,6 +973,7 @@ class _ProfileTabState extends State { arguments: { 'id': getEditProfileIndi!.data!.id, + 'iscommunity' : false, }); }, child: text16400white('View more')) diff --git a/lib/Utils/Common/CommonAppbar.dart b/lib/Utils/Common/CommonAppbar.dart index 9cd5b5b..10c5475 100644 --- a/lib/Utils/Common/CommonAppbar.dart +++ b/lib/Utils/Common/CommonAppbar.dart @@ -29,33 +29,36 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/CommonGlassmorphism.dart'; +import 'package:regroup/Common/controller/MainScreen.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; +import 'package:regroup/resources/routes/route_name.dart'; class CommonAppbar extends StatelessWidget implements PreferredSizeWidget { @override Size get preferredSize => Size.fromHeight(height); - const CommonAppbar({ - Key? key, - required this.titleTxt, - this.showLeading = true, - this.customActionWidget, - this.onCustomActionPressed, - this.showEdit = false, - this.customBack, - this.editPageName, - this.height = 80, - }) : super(key: key); + const CommonAppbar( + {Key? key, + required this.titleTxt, + this.showLeading = true, + this.customActionWidget, + this.onCustomActionPressed, + this.showEdit = false, + this.customBack = false, + this.editPageName, + this.height = 80, + this.customRouteName}) + : super(key: key); final String titleTxt; final bool? showLeading; final Widget? customActionWidget; final VoidCallback? onCustomActionPressed; final bool? showEdit; - final bool? customBack; + final bool customBack; final String? editPageName; final double height; - + final String? customRouteName; @override Widget build(BuildContext context) { return PreferredSize( @@ -125,7 +128,11 @@ class CommonAppbar extends StatelessWidget implements PreferredSizeWidget { padding: EdgeInsets.only(top: 10.h), child: InkWell( onTap: () { - Get.back(); + if (customBack) { + Get.back(result: true); + } else { + Get.back(); + } }, child: Row( children: [ diff --git a/lib/Utils/Common/ShimmerCommon.dart b/lib/Utils/Common/ShimmerCommon.dart index 8c2ce55..392b225 100644 --- a/lib/Utils/Common/ShimmerCommon.dart +++ b/lib/Utils/Common/ShimmerCommon.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shimmer/shimmer.dart'; class ShimmerCommon extends StatelessWidget { @@ -12,15 +13,17 @@ class ShimmerCommon extends StatelessWidget { // Build shimmer effect for the body Widget _buildShimmerBody() { - return ListView.builder( + return ListView.separated( + separatorBuilder: (context, index) { + return SizedBox( + height: 10.h, + ); + }, shrinkWrap: true, scrollDirection: Axis.vertical, itemCount: 4, itemBuilder: (context, index) { - return SizedBox( - height: MediaQuery.of(context).size.height > 700 ? 220 : 270, - child: _buildShimmerInsightWidget(), - ); + return _buildShimmerInsightWidget(); }, ); } @@ -28,36 +31,121 @@ class ShimmerCommon extends StatelessWidget { // Build shimmer UI for InsightWidget Widget _buildShimmerInsightWidget() { return Shimmer.fromColors( - baseColor: Colors.grey[500]!, - highlightColor: Colors.grey[300]!, + baseColor: Colors.white12, + highlightColor: Colors.white24, child: Container( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( - width: double.infinity, - height: 20, - color: Colors.grey[500], + Row( + children: [ + CircleAvatar( + radius: 25.r, + backgroundColor: Colors.grey[300], + ), + SizedBox(width: 12.w), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 100.w, + height: 16.h, + color: Colors.grey[300], + ), + SizedBox(height: 5.h), + Row( + children: [ + Container( + width: 14.w, + height: 14.w, + color: Colors.grey[300], + ), + SizedBox(width: 7.w), + Container( + width: 60.w, + height: 12.h, + color: Colors.grey[300], + ), + SizedBox(width: 7.w), + Container( + width: 4.sp, + height: 4.sp, + color: Colors.grey[300], + ), + SizedBox(width: 6.w), + Container( + width: 30.w, + height: 12.h, + color: Colors.grey[300], + ), + ], + ) + ], + ), + Spacer(), + Container( + width: 16.w, + height: 18.h, + color: Colors.grey[300], + ), + SizedBox(width: 5.w), + ], ), - const SizedBox(height: 8), + SizedBox(height: 20.h), Container( + height: 360.h, width: double.infinity, - height: 20, - color: Colors.grey[500], - ), - const SizedBox(height: 8), - Container( - width: double.infinity, - height: 20, - color: Colors.grey[500], - ), - const SizedBox(height: 8), - Container( - width: double.infinity, - height: 20, - color: Colors.grey[500], + color: Colors.grey[300], ), + SizedBox(height: 20.h), + Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + // Container( + // width: 30.w, + // height: 30.h, + // color: Colors.grey[300], + // ), + CircleAvatar( + radius: 20.r, + backgroundColor: Colors.grey[300], + ), + SizedBox(width: 12.w), + Container( + width: 60.w, + height: 14.h, + color: Colors.grey[300], + ), + SizedBox(width: 20.w), + CircleAvatar( + radius: 20.r, + backgroundColor: Colors.grey[300], + ), + SizedBox(width: 12.w), + Container( + width: 60.w, + height: 14.h, + color: Colors.grey[300], + ), + SizedBox(width: 12.w), + CircleAvatar( + radius: 20.r, + backgroundColor: Colors.grey[300], + ), + ], + ), + SizedBox(height: 12.h), + Container( + height: 1.h, + width: double.infinity, + color: Colors.grey[300], + ), + SizedBox(height: 12.h), + ], + ) ], ), ), diff --git a/lib/sidemenu/Community/Group/view/Group.dart b/lib/sidemenu/Community/Group/view/Group.dart index 8aa14ef..b77bee3 100644 --- a/lib/sidemenu/Community/Group/view/Group.dart +++ b/lib/sidemenu/Community/Group/view/Group.dart @@ -4,6 +4,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/CommonGlassmorphism.dart'; import 'package:regroup/Common/CommonWidget.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/view_model/getmethod.dart'; import 'package:regroup/sidemenu/view_model/getmethod.dart'; import 'package:regroup/Utils/Common/CommonAppbar.dart'; @@ -41,12 +42,13 @@ class _GroupState extends State { late Future myfuture; int id = Get.arguments["id"]; + bool iscommunity = Get.arguments["iscommunity"]; @override void initState() { // TODO: implement initState - myfuture = Sidegetmethod().getJoinedusergroups(id); + // myfuture = Sidegetmethod().getJoinedusergroups(id); super.initState(); } @@ -60,37 +62,69 @@ class _GroupState extends State { titleTxt: "Groups", ), resizeToAvoidBottomInset: false, - body: FutureBuilder( - future: myfuture, - builder: (ctx, snapshot) { - if (snapshot.data == null) { - return const Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Center( - child: CircularProgressIndicator( - color: Color(0xFFC18948), - ), - ) - ], - ); - } - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasError) { - return Center( - child: Text( - '${snapshot.error} occured', - style: TextStyle(fontSize: 18.spMin), - ), - ); - } - } - return joinedgroupsobj!.data!.isEmpty - ? _buildNoDataBody(context) - : _buildBody(context); - }, - ), + body: iscommunity == true + ? FutureBuilder( + future: Getcommunity().getCommunitygroups(1), + builder: (ctx, snapshot) { + if (snapshot.data == null) { + return const Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Center( + child: CircularProgressIndicator( + color: Color(0xFFC18948), + ), + ) + ], + ); + } + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occured', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + } + return communitygroupspobj!.data.isEmpty + ? _buildNoDataBody(context) + : _communitybuildBody(context); + }, + ) + : FutureBuilder( + future: Sidegetmethod().getJoinedusergroups(id), + builder: (ctx, snapshot) { + if (snapshot.data == null) { + return const Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Center( + child: CircularProgressIndicator( + color: Color(0xFFC18948), + ), + ) + ], + ); + } + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occured', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + } + return joinedgroupsobj!.data!.isEmpty + ? _buildNoDataBody(context) + : _buildBody(context); + }, + ), ); } @@ -371,7 +405,262 @@ class _GroupState extends State { ]); } - + Widget _communitybuildBody(context) { + 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), + child: SingleChildScrollView( + child: Column( + children: [ + ListView.builder( + shrinkWrap: true, + physics: ScrollPhysics(), + itemCount: communitygroupspobj!.data.length, + itemBuilder: (context, index) { + return Padding( + padding: EdgeInsets.only(bottom: 25.h), + child: GestureDetector( + onTap: () {}, + child: commonGlassUI( + borderwidth: 0.9, + width: double.infinity, + height: 162.h, + borderRadius: BorderRadius.circular(10.r), + customWidget: Padding( + padding: EdgeInsets.symmetric( + horizontal: 16.w, vertical: 16.h), + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 65.h, + width: 65.h, + decoration: BoxDecoration( + shape: BoxShape.circle, + // color: Colors.amber, + ), + child: + // Center( + // child: Image.asset(imagepath, fit: BoxFit.cover)), + communitygroupspobj! + .data[index] + .groups! + .groupImage == + null || + communitygroupspobj! + .data[index] + .groups! + .groupImage! + .isEmpty + ? CircleAvatar( + backgroundImage: AssetImage( + 'assets/images/png/img45.png', + ), + ) + : CircleAvatar( + backgroundImage: + NetworkImage( + communitygroupspobj! + .data[index] + .groups! + .groupImage!), + )), + sizedBoxWidth(13.w), + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + // Container( + // // width: 250.w, + // // color: Colors.red, + // width: double.infinity, + // child: + communitygroupspobj!.data[index].groups! + .title == + null || + communitygroupspobj!.data[index] + .groups!.title!.isEmpty + ? text18w700_FCFCFC('Regroup') + : SizedBox( + width: 200.w, + child: text18w700_FCFCFC( + communitygroupspobj! + .data[index] + .groups! + .title!), + ), + // ), + sizedBoxHeight(10.h), + communitygroupspobj!.data[index] + .communityData == + null || + communitygroupspobj! + .data[index] + .communityData! + .communityName! + .isEmpty + ? SizedBox() + : Row( + children: [ + Image.asset( + 'assets/images/png/community 1 (traced).png', + width: 18.w, + height: 18.h, + ), + sizedBoxWidth(4.w), + text14w400_FCFCFCblur( + communitygroupspobj! + .data[index] + .communityData! + .communityName!) + ], + ), + ], + ), + Spacer(), + PopupMenuButton( + surfaceTintColor: + const Color(0xFF222935), + constraints: BoxConstraints.tightFor( + width: 200.w), + offset: const Offset(0, 30), + color: const Color(0xFF222935), + tooltip: "", + itemBuilder: (BuildContext context) => + [ + PopupMenuItem( + onTap: () {}, + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.w), + child: Row( + children: [ + text14w400_FCFCFC( + "Mute group"), + const Spacer(), + Image.asset( + "assets/images/png/Black (1).png", + height: 18.h, + width: 18.w, + ) + ], + ), + ), + ), + const PopupMenuDivider(), + PopupMenuItem( + onTap: () {}, + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.w), + child: Row( + children: [ + text14w400_FCFCFC( + "Pin group"), + const Spacer(), + Image.asset( + "assets/images/png/f7_pin-fill (2).png", + height: 27.h, + width: 27.w, + ) + ], + ), + ), + ), + const PopupMenuDivider(), + PopupMenuItem( + onTap: () {}, + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.w), + child: Row( + children: [ + text14w400_FCFCFC( + "Make primary"), + const Spacer(), + Image.asset( + "assets/images/png/leave group.png", + height: 20.h, + width: 20.w, + ) + ], + ), + ), + ), + const PopupMenuDivider(), + PopupMenuItem( + onTap: () {}, + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.w), + child: Row( + children: [ + // text14w400_FCFCFC("Leave group"), + text14w400_D90B2E( + "Leave group"), + const Spacer(), + Image.asset( + "assets/images/png/LightGray22.png", + height: 18.h, + width: 18.w, + ) + ], + ), + ), + ), + ], + child: Image.asset( + "assets/images/png/Group 1000004071.png", + height: 18.h, + width: 20.w, + )), + ], + ), + sizedBoxHeight(16.h), + commonDivider(), + sizedBoxHeight(10.h), + Row( + children: [ + stackContainersGroups( + number: communitygroupspobj! + .data[index].groups!.totalMember + .toString(), + containerImages: communitygroupspobj! + .data[index].groups!.sevenMemberImage + .map((photo) => photo + .iamPrincipalData!.profilePhoto!) + .toList(), + ), + sizedBoxWidth(75.w), + communitygroupspobj!.data[index].groups == + null || + communitygroupspobj!.data[index] + .groups!.totalMember.isBlank! + ? SizedBox() + : text16w400_FCFCFC_blur( + '${communitygroupspobj!.data[index].groups!.totalMember} members', + ), + ], + ) + ], + ), + )), + ), + ); + }, + ) + ], + ))) + ]); + } // Widget groupCard({ // required String? imagepath, diff --git a/lib/sidemenu/Community/MyCommunity/AddGroups.dart b/lib/sidemenu/Community/MyCommunity/AddGroups.dart index ff8d140..6d7dcba 100644 --- a/lib/sidemenu/Community/MyCommunity/AddGroups.dart +++ b/lib/sidemenu/Community/MyCommunity/AddGroups.dart @@ -1,15 +1,28 @@ +import 'dart:async'; +import 'dart:developer'; +import 'dart:io'; + +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'; +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}); @@ -43,6 +56,99 @@ class _AddGroupState extends State { "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( @@ -53,6 +159,17 @@ class _AddGroupState extends State { 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( @@ -81,122 +198,198 @@ class _AddGroupState extends State { ), ), 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), + // 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), ]), ), - ListView.builder( - shrinkWrap: true, - itemCount: groupData.length, - itemBuilder: (context, index) { - return Column( - children: [ - groupWidget( - index: index, - imagePath: groupData[index]["imagePath"], - title: groupData[index]["title"], - subtitle: groupData[index]["subtitle"], - isChecked: isCheckedList[index], - onCheckedChanged: (bool? value) { - isCheckedList[index] = value ?? false; - }, - ), - commonDivider(), - ], - ); - }, - ), + 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), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: CommonBtn( - text: "Add", - onTap: () { - Get.toNamed(RouteName.mycommunity); - }, - ), - ), ]), ) ])); } + 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 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: [ - CircleAvatar( - backgroundImage: AssetImage(imagePath), - radius: 20.r, - ), - sizedBoxWidth(10.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC(title), - sizedBoxHeight(4.h), - text12w400_FCFCFC_blur(subtitle), - ], - ), - Spacer(), - Obx(() { - return commonGlassUI( - borderwidth: isCheckedList[index] ? 1.2 : 0.9, - borderRadius: BorderRadius.circular( 2), - height: 23.h, - width: 23.w, - opacity1: 0.24, - opacity2: 0.24, - borderColor: - isCheckedList[index] ? Color(0xFFD90B2E) : Color(0xFF434A53), - customWidget: Transform.scale( - scale: 1, - child: Checkbox( - side: BorderSide(color: Colors.transparent), - value: isCheckedList[index], - activeColor: Colors.transparent, - checkColor: Color(0xFFD90B2E), - onChanged: onCheckedChanged, + 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, ), - )); - }) - ]), + 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, + ), + ), + ), + ], + ), ); } } diff --git a/lib/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart b/lib/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart new file mode 100644 index 0000000..a7f27dc --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart @@ -0,0 +1,101 @@ +class CommunityAddgroupsModel { + CommunityAddgroupsModel({ + required this.status, + required this.statusCode, + required this.message, + required this.data, + }); + + final String? status; + final int? statusCode; + final String? message; + final List data; + + factory CommunityAddgroupsModel.fromJson(Map json){ + return CommunityAddgroupsModel( + status: json["status"], + statusCode: json["status_code"], + message: json["message"], + data: json["data"] == null ? [] : List.from(json["data"]!.map((x) => Datum.fromJson(x))), + ); + } + +} + +class Datum { + Datum({ + required this.id, + required this.title, + required this.groupImage, + required this.description, + required this.totalMember, + required this.sevenMemberImage, + }); + + final int? id; + final String? title; + final String? groupImage; + final String? description; + final int? totalMember; + final List sevenMemberImage; + + factory Datum.fromJson(Map json){ + return Datum( + id: json["id"], + title: json["title"], + groupImage: json["group_image"], + description: json["description"], + totalMember: json["total_member"], + sevenMemberImage: json["seven_member_image"] == null ? [] : List.from(json["seven_member_image"]!.map((x) => SevenMemberImage.fromJson(x))), + ); + } + +} + +class SevenMemberImage { + SevenMemberImage({ + required this.id, + required this.iamPrincipalXid, + required this.manageGroupXid, + required this.iamPrincipalData, + }); + + final int? id; + final int? iamPrincipalXid; + final int? manageGroupXid; + final IamPrincipalData? iamPrincipalData; + + factory SevenMemberImage.fromJson(Map json){ + return SevenMemberImage( + id: json["id"], + iamPrincipalXid: json["iam_principal_xid"], + manageGroupXid: json["manage_group_xid"], + iamPrincipalData: json["iam_principal_data"] == null ? null : IamPrincipalData.fromJson(json["iam_principal_data"]), + ); + } + +} + +class IamPrincipalData { + IamPrincipalData({ + required this.id, + required this.principalTypeXid, + required this.profilePhoto, + required this.isUserPinned, + }); + + final int? id; + final int? principalTypeXid; + final String? profilePhoto; + final bool? isUserPinned; + + factory IamPrincipalData.fromJson(Map json){ + return IamPrincipalData( + id: json["id"], + principalTypeXid: json["principal_type_xid"], + profilePhoto: json["profile_photo"], + isUserPinned: json["is_user_pinned"], + ); + } + +} diff --git a/lib/sidemenu/Community/MyCommunity/Model/communitygroupsModel.dart b/lib/sidemenu/Community/MyCommunity/Model/communitygroupsModel.dart new file mode 100644 index 0000000..09fcefd --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/Model/communitygroupsModel.dart @@ -0,0 +1,161 @@ +class CommunitygroupsModel { + CommunitygroupsModel({ + required this.status, + required this.statusCode, + required this.message, + required this.data, + }); + + final String? status; + final int? statusCode; + final String? message; + final List data; + + factory CommunitygroupsModel.fromJson(Map json){ + return CommunitygroupsModel( + status: json["status"], + statusCode: json["status_code"], + message: json["message"], + data: json["data"] == null ? [] : List.from(json["data"]!.map((x) => Datum.fromJson(x))), + ); + } + +} + +class Datum { + Datum({ + required this.manageCommunityXid, + required this.manageGroupXid, + required this.groups, + required this.communityData, + }); + + final int? manageCommunityXid; + final int? manageGroupXid; + final Groups? groups; + final CommunityData? communityData; + + factory Datum.fromJson(Map json){ + return Datum( + manageCommunityXid: json["manage_community_xid"], + manageGroupXid: json["manage_group_xid"], + groups: json["groups"] == null ? null : Groups.fromJson(json["groups"]), + communityData: json["community_data"] == null ? null : CommunityData.fromJson(json["community_data"]), + ); + } + +} + +class CommunityData { + CommunityData({ + required this.id, + required this.communityName, + required this.totalGroup, + required this.totalAnnouncements, + }); + + final int? id; + final String? communityName; + final int? totalGroup; + final int? totalAnnouncements; + + factory CommunityData.fromJson(Map json){ + return CommunityData( + id: json["id"], + communityName: json["community_name"], + totalGroup: json["total_group"], + totalAnnouncements: json["total_announcements"], + ); + } + +} + +class Groups { + Groups({ + required this.id, + required this.totalMember, + required this.sevenMemberImage, + required this.manageGroupTypeXid, + required this.title, + required this.backgroundImage, + required this.groupImage, + required this.location, + required this.link, + required this.description, + }); + + final int? id; + final int? totalMember; + final List sevenMemberImage; + final int? manageGroupTypeXid; + final String? title; + final String? backgroundImage; + final String? groupImage; + final String? location; + final String? link; + final String? description; + + factory Groups.fromJson(Map json){ + return Groups( + id: json["id"], + totalMember: json["total_member"], + sevenMemberImage: json["seven_member_image"] == null ? [] : List.from(json["seven_member_image"]!.map((x) => SevenMemberImage.fromJson(x))), + manageGroupTypeXid: json["manage_group_type_xid"], + title: json["title"], + backgroundImage: json["background_image"], + groupImage: json["group_image"], + location: json["location"], + link: json["link"], + description: json["description"], + ); + } + +} + +class SevenMemberImage { + SevenMemberImage({ + required this.id, + required this.iamPrincipalXid, + required this.manageGroupXid, + required this.iamPrincipalData, + }); + + final int? id; + final int? iamPrincipalXid; + final int? manageGroupXid; + final IamPrincipalData? iamPrincipalData; + + factory SevenMemberImage.fromJson(Map json){ + return SevenMemberImage( + id: json["id"], + iamPrincipalXid: json["iam_principal_xid"], + manageGroupXid: json["manage_group_xid"], + iamPrincipalData: json["iam_principal_data"] == null ? null : IamPrincipalData.fromJson(json["iam_principal_data"]), + ); + } + +} + +class IamPrincipalData { + IamPrincipalData({ + required this.id, + required this.principalTypeXid, + required this.profilePhoto, + required this.isUserPinned, + }); + + final int? id; + final int? principalTypeXid; + final String? profilePhoto; + final bool? isUserPinned; + + factory IamPrincipalData.fromJson(Map json){ + return IamPrincipalData( + id: json["id"], + principalTypeXid: json["principal_type_xid"], + profilePhoto: json["profile_photo"], + isUserPinned: json["is_user_pinned"], + ); + } + +} diff --git a/lib/sidemenu/Community/MyCommunity/NewCommunity.dart b/lib/sidemenu/Community/MyCommunity/NewCommunity.dart index f5f331f..bd23833 100644 --- a/lib/sidemenu/Community/MyCommunity/NewCommunity.dart +++ b/lib/sidemenu/Community/MyCommunity/NewCommunity.dart @@ -1,19 +1,32 @@ +import 'dart:developer'; import 'dart:io'; +import 'dart:async'; +import 'package:dio/dio.dart'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:get/get.dart'; +import 'package:get/get.dart' hide MultipartFile, FormData; +import 'package:get/get_connect/http/src/utils/utils.dart'; import 'package:regroup/Common/CommonButton.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/CustomTextformfield.dart'; import 'package:regroup/Utils/Common/ImageUpload.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:regroup/sidemenu/Community/MyCommunity/view_model/postmethod.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart'; +import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart'; +import 'package:path/path.dart' as path; class NewCommunity extends StatefulWidget { const NewCommunity({super.key}); @@ -28,214 +41,429 @@ class _NewCommunityState extends State { bool isImageAdded = false; bool isbannerAdded = false; + + TextEditingController communitycontroller = TextEditingController(); + TextEditingController locationcontroller = TextEditingController(); + TextEditingController communitydescrcontroller = TextEditingController(); + + final Map _TypecommunityMap = { + 'Public': 1, + 'Private': 2, + 'Secret': 3, + }; + + String _selectedtypecommunity = ''; + + void _onItemSelected(String value) { + setState(() { + _selectedtypecommunity = value; + }); + } + + primaryactlist.InterestModel? abilityModel; + List activity = []; + List _activitydrop = []; + + Future fetchActivitylist() async { + PrimaryActivityListApi abilityLsitAPI = PrimaryActivityListApi(); + ResponseData response = await abilityLsitAPI.getActivitylistApi(); + + if (response.status == ResponseStatus.SUCCESS) { + abilityModel = primaryactlist.InterestModel.fromJson(response.data!); + setState(() { + activity = abilityModel!.data ?? []; // Store the fetched cities + _activitydrop = + activity.map((platform) => platform.name.toString()).toList(); + }); + log(activity.toString()); + } else { + print('Failed to fetch abilities'); + } + } + + int? selectedactivityid; + + void getCatIdFromName(String selectedAbility) { + // Clear existing selections + selectedactivityid = null; + + // Find and add the ID of the selected ability + for (var activityItem in activity) { + if (selectedAbility == activityItem.name) { + selectedactivityid = activityItem.id!; + break; // Stop once the matching item is found + } + } + print('selected activity is $selectedactivityid'); + } + + @override + void initState() { + // TODO: implement initState + fetchActivitylist(); + super.initState(); + } + + // 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), + // ), + // ); + // } + + // int communityTypeValue = _TypecommunityMap[_selectedtypecommunity] ?? 0; + + // FormData formdata = FormData.fromMap({ + // "community_profile_photo": profielpicturelist[0], + // "community_banner_image": bannermedialist[0], + // "community_name": communitycontroller.text, + // "community_location": locationcontroller.text, + // "community_description": communitydescrcontroller.text, + // 'community_type_xid': communityTypeValue, + // 'activity_xid': selectedactivityid, + // }); + // final data = await PostMethodCommunity().postCreatecommunity(formdata); + // if (data.status == ResponseStatus.SUCCESS) { + // Get.back(); + // print("community created"); + // Get.toNamed(RouteName.addgroup); + + // 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, - resizeToAvoidBottomInset: false, - appBar: CommonAppbar( - titleTxt: "New community", - ), - body: Stack(children: [ - Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/png/Ellipse 1496.png"), - fit: BoxFit.fill)), + return GestureDetector( + onTap: () => FocusManager.instance.primaryFocus?.unfocus(), + child: Scaffold( + // key: _scaffoldKey1, + backgroundColor: Color(0xFF222935), + extendBody: true, + resizeToAvoidBottomInset: false, + appBar: CommonAppbar( + titleTxt: "New community", ), - SingleChildScrollView( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w), - child: - Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - sizedBoxHeight(20.h), - Center( - child: InkWell( - onTap: () { - ImageUploadBottomSheet().showModal( - context, - true, - (result) { - var file = File(result); - - filePath.add(file); - isImageAdded = true; - setState(() {}); - }, - ); - }, - child: commonGlassUI( - width: 95.w, - height: 95.h, - borderRadius: BorderRadius.circular( 100), - opacity1: 0.24, - opacity2: 0.24, - customWidget: filePath.isNotEmpty && isImageAdded - ? ClipOval( - child: SizedBox.fromSize( - size: Size.fromRadius(47.5.r), - child: Image.file( - filePath[0]!, - fit: BoxFit.cover, - width: double.infinity, - ), - ), - ) - : Center( - child: Image.asset( - "assets/images/png/cameraicon2.png", - height: 30.h, - width: 30.w, - ), - ), - borderwidth: 0.5), - ), - ), - sizedBoxHeight(20.h), - Center(child: text16w400_white("Add community profile picture")), - sizedBoxHeight(30.h), - text16w400_FCFCFC("Banner image"), - sizedBoxHeight(15.h), - InkWell( - onTap: () { - ImageUploadBottomSheet().showModal( - context, - false, - (result) { - var file = File(result); - - 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: 130.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)), + body: Stack(children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill)), + ), + SingleChildScrollView( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 16.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + sizedBoxHeight(20.h), + Center( + 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 { + // Handle case where no image is selected + bannerPath.clear(); + isbannerAdded = false; + setState(() {}); + } + }, + ); + }, + child: commonGlassUI( + width: 95.w, + height: 95.h, + borderRadius: BorderRadius.circular(100), + opacity1: 0.24, + opacity2: 0.24, + customWidget: filePath.isNotEmpty && isImageAdded + ? ClipOval( + child: SizedBox.fromSize( + size: Size.fromRadius(47.5.r), + child: Image.file( + filePath[0]!, + fit: BoxFit.cover, + width: double.infinity, ), - child: Icon( - Icons.delete_outline_outlined, - color: Colors.white, - ))), - ), - ]) - : Padding( - padding: EdgeInsets.symmetric(vertical: 16.h), - child: Column( - children: [ - Image.asset( - "assets/images/png/bi_download.png", - height: 36.h, - width: 36.w, + ), + ) + : Center( + child: Image.asset( + "assets/images/png/cameraicon2.png", + height: 30.h, + width: 30.w, + ), + ), + borderwidth: 0.5), + ), + ), + sizedBoxHeight(20.h), + Center( + child: + text16w400_white("Add community profile picture")), + sizedBoxHeight(30.h), + text16w400_FCFCFC("Banner image"), + sizedBoxHeight(15.h), + InkWell( + onTap: () { + ImageUploadBottomSheet().showModal( + context, + false, + (result) { + // var file = File(result); + + // bannerPath.add(file); + // isbannerAdded = true; + // setState(() {}); + 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: 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: 130.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/bi_download.png", + height: 36.h, + width: 36.w, + ), + sizedBoxHeight(10.h), + text14w400white('Upload banner image'), + sizedBoxHeight(8.h), + text8w400_8A8A8A( + "Allowed file extensions: jpg, png, gif Max file size: 10 MB"), + ], + ), ), - sizedBoxHeight(10.h), - text14w400white('Upload banner image'), - sizedBoxHeight(8.h), - text8w400_8A8A8A( - "Allowed file extensions: jpg, png, gif Max file size: 10 MB"), - ], - ), - ), - ), - ), - ), - sizedBoxHeight(25.h), + ), + ), + ), + sizedBoxHeight(25.h), - text16w400_FCFCFC("Community name*"), - sizedBoxHeight(15.h), - CustomTextFormField( - validator: (val) { - if (val == null || val.isEmpty) { - return 'Enter Community name'; - } - return null; - }, - ), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Type of community*"), - sizedBoxHeight(15.h), - CustomDropDownRadio( - header: "", - title: "", - listData: ['Public', 'Private', 'Secret'], - onItemSelected: (p0) {}, - leadingImage: SizedBox()), - // CommonDropdownradioBtn( - // hint: '', - // items: ['Public', 'Private', 'Secret'], - // showOtherOption: false), - sizedBoxHeight(25.h), - text16w400_FCFCFC("Location*"), - sizedBoxHeight(15.h), - CustomDropDownRadio( - header: "", - title: "", - listData: ['Public', 'Private', 'Secret'], - onItemSelected: (p0) {}, - leadingImage: SizedBox()), + text16w400_FCFCFC("Community name*"), + sizedBoxHeight(15.h), + CustomTextFormField( + textEditingController: communitycontroller, + inputFormatters: [ + RemoveEmojiInputFormatter(), + // FilteringTextInputFormatter.allow(RegExp('[a-zA-Z ]')) + ], + hintText: 'Enter community name', + validator: (val) { + if (val == null || val.isEmpty) { + return 'Enter Community name'; + } + return null; + }, + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Community description*"), + sizedBoxHeight(15.h), + CustomTextFormField( + textEditingController: communitydescrcontroller, + inputFormatters: [ + RemoveEmojiInputFormatter(), + // FilteringTextInputFormatter.allow(RegExp('[a-zA-Z ]')) + ], + hintText: 'Enter community description', + validator: (val) { + if (val == null || val.isEmpty) { + return 'Enter Community description'; + } + return null; + }, + ), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Type of community*"), + sizedBoxHeight(15.h), + CustomDropDownRadio( + header: "", + title: "", + listData: const ['Public', 'Private', 'Secret'], + onItemSelected: _onItemSelected, + // (p0) {}, + leadingImage: SizedBox()), + // CommonDropdownradioBtn( + // hint: '', + // items: ['Public', 'Private', 'Secret'], + // showOtherOption: false), + sizedBoxHeight(25.h), + text16w400_FCFCFC("Location*"), + sizedBoxHeight(15.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(25.h), - text16w400_FCFCFC("Primary activity*"), + sizedBoxHeight(20.h), + CustomDropDownRadio( + header: "", + title: "", + listData: _activitydrop, + // [ + // 'Sports', + // 'Hobby', + // ], + showOtherOption: false, + onItemSelected: getCatIdFromName, + leadingImage: SizedBox()), - sizedBoxHeight(20.h), - CustomDropDownRadio( - header: "", - title: "", - listData: [ - 'Sports', - 'Hobby', - ], - showOtherOption: true, - onItemSelected: (p0) {}, - leadingImage: SizedBox()), + sizedBoxHeight(25.h), + sizedBoxHeight(25.h), + CustomButton( + text: "Create community", + onPressed: () { + // Get.toNamed(RouteName.addgroup); + if (bannerPath.isEmpty || + communitycontroller.text.isEmpty || + communitydescrcontroller.text.isEmpty || + _selectedtypecommunity.isEmpty || + locationcontroller.text.isEmpty || + selectedactivityid.isBlank!) { + utils.showToast('Please fill all fields'); + } else if (filePath.isEmpty) { + utils.showToast( + 'Please add community profile picture'); + } else { + print('done'); + // indiUploadata(); + // Uploadata(); + int communityTypeValue = _TypecommunityMap[_selectedtypecommunity] ?? 0; - sizedBoxHeight(25.h), - sizedBoxHeight(25.h), - CommonBtn( - text: "Create community", - onTap: () { - Get.toNamed(RouteName.addgroup); - }, - ), - sizedBoxHeight(25.h), - sizedBoxHeight(150.h), - ]), - )) - ])); + Get.toNamed(RouteName.addgroup,arguments: { + 'communityname' : communitycontroller.text, + 'communitylocation' : locationcontroller.text, + 'communitydescription' : communitydescrcontroller.text, + 'communitytype' : communityTypeValue, + 'activityid' : selectedactivityid, + 'communityprofilephoto' : filePath, + 'communitybannerimage' : bannerPath, + }); + + } + }, + ), + sizedBoxHeight(25.h), + sizedBoxHeight(150.h), + ]), + )) + ])), + ); } } diff --git a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart index 3db037b..94f998b 100644 --- a/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart +++ b/lib/sidemenu/Community/MyCommunity/View/CommunityDetails.dart @@ -20,6 +20,13 @@ class CommunityDetails extends StatefulWidget { class _CommunityDetailsState extends State { bool? additionalContent = false; + var CommunityId; + @override + void initState() { + // TODO: implement initState + CommunityId = Get.arguments["CommunityID"]; + super.initState(); + } @override Widget build(BuildContext context) { diff --git a/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart b/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart index ddaacd4..2374dff 100644 --- a/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart +++ b/lib/sidemenu/Community/MyCommunity/View/MyCommunity.dart @@ -200,7 +200,7 @@ class _MyCommunityState extends State { padding: EdgeInsets.only(bottom: 25.h), child: GestureDetector( onTap: () { - Get.toNamed(RouteName.communityDetails); + Get.toNamed(RouteName.communityDetails, arguments: {"CommunityID" : joinnedComData.manageCommunityXid}); }, child: commonGlassUI( borderwidth: 0.9, diff --git a/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart b/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart new file mode 100644 index 0000000..fc9ad63 --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/view_model/getmethod.dart @@ -0,0 +1,44 @@ +import 'dart:async'; +import 'dart:developer'; + +import 'package:regroup/Common/api_urls.dart'; +import 'package:regroup/Common/base_manager.dart'; +import 'package:regroup/Common/controller/data/network/network_api.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/Model/communityaddgroupsModel.dart'; +import 'package:regroup/sidemenu/Community/MyCommunity/Model/communitygroupsModel.dart'; + +CommunityAddgroupsModel? communityaddgroupobj; +CommunitygroupsModel? communitygroupspobj; + + + +class Getcommunity { + + Future> getCommunityAddGroupsearch(updata, + {required StreamController streamController}) async { + final response = + await NetworkApiServices().getApi( + "${ApiUrls.getcommunityaddgroups}?search=$updata", + + ); + + if (response.status == ResponseStatus.SUCCESS) { + communityaddgroupobj = CommunityAddgroupsModel.fromJson(response.data); + if (!streamController.isClosed) streamController.sink.add(communityaddgroupobj!); + } + return response; + } + + Future> getCommunitygroups(updata) async { + final response = await NetworkApiServices().getApi( + "${ApiUrls.getcommunitygroups}?manage_community_xid=$updata", + // optionalpar: false + ); + if (response.status == ResponseStatus.SUCCESS) { + communitygroupspobj = CommunitygroupsModel.fromJson(response.data); + log(communitygroupspobj!.data.toString()); + } + return response; + } + +} \ No newline at end of file diff --git a/lib/sidemenu/Community/MyCommunity/view_model/postmethod.dart b/lib/sidemenu/Community/MyCommunity/view_model/postmethod.dart new file mode 100644 index 0000000..6e43862 --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/view_model/postmethod.dart @@ -0,0 +1,18 @@ +import 'package:regroup/Common/api_urls.dart'; +import 'package:regroup/Common/base_manager.dart'; +import 'package:regroup/Common/controller/data/network/network_api.dart'; + +class PostMethodCommunity { + PostMethodCommunity(); + + Future> postCreatecommunity(updata) async { + print("updata is $updata"); + final response = await NetworkApiServices().postApi( + updata, + ApiUrls.postcreatecommunity, + ); + print("response is ${response.data}"); + print("response message is ${response.message}"); + return response; + } +} \ No newline at end of file diff --git a/lib/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart b/lib/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart new file mode 100644 index 0000000..818fd9c --- /dev/null +++ b/lib/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart @@ -0,0 +1,32 @@ +import 'package:regroup/Common/api_urls.dart'; +import 'package:regroup/Common/base_manager.dart'; +import 'package:regroup/Common/controller/data/network/network_api.dart'; +import 'package:regroup/Main_Screens/ProfileTab/EditProfile/Model/InterestModel.dart'; + +InterestModel? interestlistobj; + + +class PrimaryActivityListApi { + PrimaryActivityListApi(); + var data = ""; + Future> getActivitylistApi() async { + final response = await NetworkApiServices().getApi( + ApiUrls.getinterestlist, + + ); + + if (response.status == ResponseStatus.SUCCESS) { + Map responseData = + Map.from(response.data); + if (responseData['status'] == "success") { + print("success"); + InterestModel interestlistobj = + InterestModel.fromJson(responseData); + } else { + // return ResponseData( + // responseData['message'], ResponseStatus.FAILED); + } + } + return response; + } +} diff --git a/pubspec.lock b/pubspec.lock index de4afa4..86fd725 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,30 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + cached_network_image: + dependency: "direct main" + description: + name: cached_network_image + sha256: "4a5d8d2c728b0f3d0245f69f921d7be90cae4c2fd5288f773088672c0893f819" + url: "https://pub.dev" + source: hosted + version: "3.4.0" + cached_network_image_platform_interface: + dependency: transitive + description: + name: cached_network_image_platform_interface + sha256: ff0c949e323d2a1b52be73acce5b4a7b04063e61414c8ca542dbba47281630a7 + url: "https://pub.dev" + source: hosted + version: "4.1.0" + cached_network_image_web: + dependency: transitive + description: + name: cached_network_image_web + sha256: "6322dde7a5ad92202e64df659241104a43db20ed594c41ca18de1014598d7996" + url: "https://pub.dev" + source: hosted + version: "1.3.0" characters: dependency: transitive description: @@ -318,6 +342,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_cache_manager: + dependency: transitive + description: + name: flutter_cache_manager + sha256: a77f77806a790eb9ba0118a5a3a936e81c4fea2b61533033b2b0c3d50bbde5ea + url: "https://pub.dev" + source: hosted + version: "3.4.0" flutter_facebook_auth: dependency: "direct main" description: @@ -880,6 +912,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.0" + octo_image: + dependency: transitive + description: + name: octo_image + sha256: "34faa6639a78c7e3cbe79be6f9f96535867e879748ade7d17c9b1ae7536293bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" path: dependency: transitive description: @@ -1048,6 +1088,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.1+1" + rxdart: + dependency: transitive + description: + name: rxdart + sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962" + url: "https://pub.dev" + source: hosted + version: "0.28.0" shared_preferences: dependency: "direct main" description: @@ -1165,6 +1213,22 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + sqflite: + dependency: transitive + description: + name: sqflite + sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d + url: "https://pub.dev" + source: hosted + version: "2.3.3+1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4" + url: "https://pub.dev" + source: hosted + version: "2.5.4" stack_trace: dependency: transitive description: @@ -1229,6 +1293,14 @@ packages: url: "https://pub.dev" source: hosted version: "21.2.10" + synchronized: + dependency: transitive + description: + name: synchronized + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + url: "https://pub.dev" + source: hosted + version: "3.1.0+1" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4571906..ce805d8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -77,6 +77,8 @@ dependencies: flutter_html: ^3.0.0-beta.2 comment_tree: ^0.3.0 flutter_keyboard_visibility: ^6.0.0 + cached_network_image: any + dev_dependencies: flutter_test: