From 6aea13e95923351cd3944953581c24e417ef62fc Mon Sep 17 00:00:00 2001 From: Dakshesh42 Date: Thu, 8 Aug 2024 19:05:36 +0530 Subject: [PATCH] populattab api integration --- lib/Common/api_urls.dart | 2 + .../Community/Model/PopularPostModel.dart | 242 ++ .../Community/ViewModel/PopularPost.dart | 26 + .../Community_HomePage/Community.dart | 2056 +++++++++++------ 4 files changed, 1558 insertions(+), 768 deletions(-) create mode 100644 lib/Main_Screens/Community/Model/PopularPostModel.dart create mode 100644 lib/Main_Screens/Community/ViewModel/PopularPost.dart diff --git a/lib/Common/api_urls.dart b/lib/Common/api_urls.dart index ae037c6..2e1bae2 100644 --- a/lib/Common/api_urls.dart +++ b/lib/Common/api_urls.dart @@ -92,6 +92,8 @@ class ApiUrls { static const getblockuser = "${baseUrl}fetch-blocked-profile"; static const postblockuser = "${baseUrl}block-profile"; static const getlatestpost = "${baseUrl}fetch-latest-post"; + static const getpopularpost = "${baseUrl}fetch-popular-post"; + static const getfeedpost = "${baseUrl}fetch-post"; static const tagcommunityuser = "${baseUrl}fetch-communities-tags-to-pin"; diff --git a/lib/Main_Screens/Community/Model/PopularPostModel.dart b/lib/Main_Screens/Community/Model/PopularPostModel.dart new file mode 100644 index 0000000..b3ef9e1 --- /dev/null +++ b/lib/Main_Screens/Community/Model/PopularPostModel.dart @@ -0,0 +1,242 @@ +class PopularpostModel { + PopularpostModel({ + 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 PopularpostModel.fromJson(Map json){ + return PopularpostModel( + 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.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 LikeIcon? 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 Datum.fromJson(Map json){ + return Datum( + 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 : LikeIcon.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) => AttachTag.fromJson(x))), + ); + } + +} + +class AttachTag { + AttachTag({ + required this.managePostXid, + required this.manageTagXid, + required this.manageTag, + }); + + final int? managePostXid; + final int? manageTagXid; + final ManageTag? manageTag; + + factory AttachTag.fromJson(Map json){ + return AttachTag( + managePostXid: json["manage_post_xid"], + manageTagXid: json["manage_tag_xid"], + manageTag: json["manage_tag"] == null ? null : ManageTag.fromJson(json["manage_tag"]), + ); + } + +} + +class ManageTag { + ManageTag({ + required this.id, + required this.isPinned, + required this.name, + }); + + final int? id; + final bool? isPinned; + final String? name; + + factory ManageTag.fromJson(Map json){ + return ManageTag( + 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 LikeIcon { + LikeIcon({ + required this.likeIconsXid, + required this.likeIcon, + }); + + final int? likeIconsXid; + final LikeIconClass? likeIcon; + + factory LikeIcon.fromJson(Map json){ + return LikeIcon( + likeIconsXid: json["like_icons_xid"], + likeIcon: json["like_icon"] == null ? null : LikeIconClass.fromJson(json["like_icon"]), + ); + } + +} + +class LikeIconClass { + LikeIconClass({ + required this.id, + required this.image, + }); + + final int? id; + final String? image; + + factory LikeIconClass.fromJson(Map json){ + return LikeIconClass( + id: json["id"], + image: json["image"], + ); + } + +} diff --git a/lib/Main_Screens/Community/ViewModel/PopularPost.dart b/lib/Main_Screens/Community/ViewModel/PopularPost.dart new file mode 100644 index 0000000..9e15b74 --- /dev/null +++ b/lib/Main_Screens/Community/ViewModel/PopularPost.dart @@ -0,0 +1,26 @@ +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/Community/Model/PopularPostModel.dart'; + +PopularpostModel? popularpostobj; + +class PopularpostApi { + PopularpostApi(); + + Future> getPopularPostApi() async { + final response = await NetworkApiServices().getApi(ApiUrls.getpopularpost); + + if (response.status == ResponseStatus.SUCCESS) { + if (response.data["status"] == "success") { + popularpostobj = PopularpostModel.fromJson(response.data); + } + return ResponseData( + response.data['message'], ResponseStatus.SUCCESS, + data: response.data); + } else { + return ResponseData( + response.data['message'], ResponseStatus.FAILED); + } + } +} \ No newline at end of file diff --git a/lib/Main_Screens/Community_HomePage/Community.dart b/lib/Main_Screens/Community_HomePage/Community.dart index 79c1a5d..8553bf9 100644 --- a/lib/Main_Screens/Community_HomePage/Community.dart +++ b/lib/Main_Screens/Community_HomePage/Community.dart @@ -3,6 +3,7 @@ import 'dart:developer'; 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'; @@ -18,8 +19,10 @@ import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart'; 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'; import 'package:regroup/Utils/Common/sized_box.dart'; @@ -124,12 +127,12 @@ class _CommunityScreenState extends State { text: 'Latest', ), ]), - Expanded( + const Expanded( child: TabBarView( children: [ - const FeedTab(), - popularTab(), - const LatestTab(), + FeedTab(), + PopularTab(), + LatestTab(), ], ), ), @@ -327,36 +330,37 @@ class _FeedTabState extends State { } else { return 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(), - postId: combinedList[index].id.toString(), - ), + // NormalCardTile( + // 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(), + // postId: combinedList[index].id.toString(), + // onSaveIconTap: () {}, + // ), sizedBoxHeight(20.h) ], ); @@ -373,22 +377,428 @@ class _FeedTabState extends State { }, ); } + + Widget announcecardtile({ + required String profileImg, + required String title, + required String mainImg, + required String create_at, + required String community_name, + required String totalcomments, + required String totalSave, + required String description, + + // required DateTime create_at, + required List containerTitle, + }) { + var 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'; + } + } + + return Column( + children: [ + commonGlassUIBlue( + width: double.infinity, + height: 780.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(profileImg), + radius: 25.r, + ), + sizedBoxWidth(12.w), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + text16w400_FCFCFC(title), + 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(community_name), + sizedBoxWidth(7.w), + Icon( + Icons.circle, + color: const Color(0xFFFCFCFC), + size: 4.sp, + ), + sizedBoxWidth(6.w), + text12w400_FCFCFC(create_at), + ], + ) + ], + ), + 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); + }, + child: Container( + height: 390.h, + decoration: BoxDecoration( + image: DecorationImage(image: NetworkImage(mainImg))), + ), + ), + 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: containerTitle.length, + itemBuilder: (context, index) { + return Padding( + padding: EdgeInsets.only(right: 12.w), + child: GestureDetector( + onTap: () { + // Get.toNamed(RouteName.cyclescreen); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + containertile2(text: containerTitle[index]), + ], + )), + ); + }, + ), + ), + sizedBoxHeight(20.h), + SizedBox( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + text16w400_FCFCFC(description), + ], + ), + ), + Row(children: [ + InkWell( + onTap: () {}, + child: stackReaction(number: '20', 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(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(totalSave), + ]), + sizedBoxHeight(12.h), + commonDivider(), + sizedBoxHeight(12.h), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Obx(() { + return ReactionButton( + onReactionChanged: (reaction) { + updateImage(reaction?.value ?? 'like'); + debugPrint( + 'Selected value: ${reaction?.value}'); + }, + reactions: ?>[ + Reaction( + value: 'like', + previewIcon: _buildReactionsPreviewIcon( + 'assets/images/png/f7_hand-thumbsup.png'), + icon: _buildReactionsIcon( + 'assets/images/png/f7_hand-thumbsup.png'), + ), + Reaction( + value: 'heart', + previewIcon: _buildReactionsPreviewIcon( + 'assets/images/png/heart 2.png'), + icon: _buildReactionsIcon( + 'assets/images/png/heart 2.png'), + ), + Reaction( + value: 'party', + previewIcon: _buildReactionsPreviewIcon( + 'assets/images/png/party-popper 2.png'), + icon: _buildReactionsIcon( + 'assets/images/png/party-popper 2.png'), + ), + ], + selectedReaction: Reaction( + value: 'like', + icon: _buildReactionsIcon( + 'assets/images/png/f7_hand-thumbsup.png'), + ), + boxColor: Colors.white, + boxElevation: 9, + boxRadius: 30, + itemsSpacing: 8, + itemScale: 0.4, + itemSize: const Size(45, 45), + boxPadding: const EdgeInsets.all(8), + boxAnimationDuration: + const Duration(milliseconds: 200), + itemAnimationDuration: + const Duration(milliseconds: 500), + hoverDuration: + const Duration(milliseconds: 700), + child: _buildReactionsIcon(mainImage.value), + ); + }) + ], + ), + 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: () {}, + child: 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), + ], + ); + } } -Widget normalcardtile2({ - required String profileImg, - required String title, - required String mainImg, - required String description, - required List containerTitle, - required String community_name, - required String total_comments, - required String total_likes, - required String total_save, - required String? create_at, - required String? postId, -}) { - var mainImage = 'assets/images/png/uiw_like-o.png'.obs; +class NormalCardTile extends StatefulWidget { + final String profileImg; + final String title; + final String mainImg; + final String description; + final List containerTitle; + 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; + + const NormalCardTile({ + Key? key, + required this.profileImg, + required this.title, + required this.mainImg, + required this.description, + required this.containerTitle, + 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, + this.create_at, + this.postId, + this.onSaveIconTap, + this.isISaved, + }) : super(key: key); + + @override + _NormalCardTileState createState() => _NormalCardTileState(); +} + +class _NormalCardTileState 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'; @@ -399,721 +809,518 @@ Widget normalcardtile2({ } } - return 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(profileImg), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC(title), - 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(community_name), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color(0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC(create_at!), - ], - ) - ], - ), - 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); - }, - child: Container( - height: 360, - width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.cover, - image: NetworkImage( - mainImg, - ), - ), - ), - ), - ), - 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: containerTitle.length, - itemBuilder: (context, index) { - return Padding( - padding: EdgeInsets.only(right: 12.w), - child: GestureDetector( - onTap: () { - // Get.toNamed(RouteName.cyclescreen, ); - // arguments: { - // 'tagid': latestpostobj!.data[index].tagsData[index].id, - // 'tagname' : latestpostobj!.data[index].tagsData[index].name, - // } - }, - child: containertile2( - text: ("#${containerTitle[index]}"))), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - width: double.infinity, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC(description), - ], - ), - ), - Row(children: [ - InkWell( - onTap: () { - Get.toNamed(RouteName.reactionview, arguments: { - 'postId': postId, - }); - }, - child: stackReaction(number: total_likes, 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(total_comments), - 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(total_save), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + // List _reactions = []; + // Map _selectedReactions = {}; + + // Future _initializeData() async { + // await _fetchIcons(); + + // 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 + // } + // } + + // 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() ?? + // []; + // for (var post in latestpostobj!.data) { + // _initializeSelectedReaction(post.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); + // } + // } + + // @override + // void initState() async { + // // TODO: implement initState + // await _initializeData(); + // super.initState(); + // } + + @override + Widget build(BuildContext context) { + return 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(widget.profileImg), + radius: 25.r, + ), + sizedBoxWidth(12.w), Column( - mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Obx(() { - return ReactionButton( - onReactionChanged: (reaction) { - updateImage(reaction?.value ?? 'like'); - debugPrint('Selected value: ${reaction?.value}'); - }, - reactions: ?>[ - Reaction( - value: 'like', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/f7_hand-thumbsup.png'), - icon: _buildReactionsIcon( - 'assets/images/png/f7_hand-thumbsup.png', - ), - ), - Reaction( - value: 'heart', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/heart 2.png'), - icon: _buildReactionsIcon( - 'assets/images/png/heart 2.png'), - ), - Reaction( - value: 'party', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/party-popper 2.png'), - icon: _buildReactionsIcon( - 'assets/images/png/party-popper 2.png'), - ), - ], - selectedReaction: Reaction( - value: 'like', - icon: _buildReactionsIcon( - 'assets/images/png/f7_hand-thumbs.png'), + text16w400_FCFCFC(widget.title), + 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(widget.community_name), + sizedBoxWidth(7.w), + Icon( + Icons.circle, + color: const Color(0xFFFCFCFC), + size: 4.sp, + ), + sizedBoxWidth(6.w), + text12w400_FCFCFC(widget.create_at!), + ], + ) + ], + ), + 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); + }, + 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, + child: ListView.builder( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + itemCount: widget.containerTitle.length, + itemBuilder: (context, index) { + return Padding( + padding: EdgeInsets.only(right: 12.w), + child: GestureDetector( + onTap: () { + // Get.toNamed(RouteName.cyclescreen, ); + // arguments: { + // 'tagid': latestpostobj!.data[index].tagsData[index].id, + // 'tagname' : latestpostobj!.data[index].tagsData[index].name, + // } + }, + child: containertile2( + text: ("#${widget.containerTitle[index]}"))), + ); + }, + ), + ), + sizedBoxHeight(20.h), + SizedBox( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + text16w400_FCFCFC(widget.description), + ], + ), + ), + 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' + ]), + ), + 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.total_comments), + 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.total_save), + ]), + 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: 2, + boxElevation: 9, boxRadius: 30, itemsSpacing: 8, itemScale: 0.4, - itemSize: const Size(45, 45), + 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), - direction: ReactionsBoxAlignment.rtl, - child: _buildReactionsIcon(mainImage.value), - ); - }) - ], - ), - GestureDetector( - onTap: () { - Get.toNamed(RouteName.postdetailsScreen); - }, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, + 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('Comment') + text11w400_FCFCFC('Like'), ], ), - ), - InkWell( - onTap: () {}, - child: Column( + GestureDetector( + onTap: () { + Get.toNamed(RouteName.postdetailsScreen); + }, + 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: [ - Image.asset( - 'assets/images/png/Frame 1000004089.png', - height: 19.h, - width: 19.w, + 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 announcecardtile({ - required String profileImg, - required String title, - required String mainImg, - required String create_at, - required String community_name, - required String totalcomments, - required String totalSave, - required String description, - - // required DateTime create_at, - required List containerTitle, -}) { - var 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'; - } - } - - return Column( - children: [ - commonGlassUIBlue( - width: double.infinity, - height: 780.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(profileImg), - radius: 25.r, - ), - sizedBoxWidth(12.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC(title), - 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(community_name), - sizedBoxWidth(7.w), - Icon( - Icons.circle, - color: const Color(0xFFFCFCFC), - size: 4.sp, - ), - sizedBoxWidth(6.w), - text12w400_FCFCFC(create_at), - ], - ) - ], - ), - 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); - }, - child: Container( - height: 390.h, - decoration: BoxDecoration( - image: DecorationImage(image: NetworkImage(mainImg))), - ), - ), - 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: containerTitle.length, - itemBuilder: (context, index) { - return Padding( - padding: EdgeInsets.only(right: 12.w), - child: GestureDetector( - onTap: () { - // Get.toNamed(RouteName.cyclescreen); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - containertile2(text: containerTitle[index]), - ], - )), - ); - }, - ), - ), - sizedBoxHeight(20.h), - SizedBox( - width: double.infinity, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text16w400_FCFCFC(description), - ], - ), - ), - Row(children: [ - InkWell( - onTap: () {}, - child: stackReaction(number: '20', 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(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(totalSave), - ]), - sizedBoxHeight(12.h), - commonDivider(), - sizedBoxHeight(12.h), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Obx(() { - return ReactionButton( - onReactionChanged: (reaction) { - updateImage(reaction?.value ?? 'like'); - debugPrint( - 'Selected value: ${reaction?.value}'); - }, - reactions: ?>[ - Reaction( - value: 'like', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/f7_hand-thumbsup.png'), - icon: _buildReactionsIcon( - 'assets/images/png/f7_hand-thumbsup.png'), - ), - Reaction( - value: 'heart', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/heart 2.png'), - icon: _buildReactionsIcon( - 'assets/images/png/heart 2.png'), - ), - Reaction( - value: 'party', - previewIcon: _buildReactionsPreviewIcon( - 'assets/images/png/party-popper 2.png'), - icon: _buildReactionsIcon( - 'assets/images/png/party-popper 2.png'), - ), - ], - selectedReaction: Reaction( - value: 'like', - icon: _buildReactionsIcon( - 'assets/images/png/f7_hand-thumbsup.png'), - ), - boxColor: Colors.white, - boxElevation: 9, - boxRadius: 30, - itemsSpacing: 8, - itemScale: 0.4, - itemSize: const Size(45, 45), - boxPadding: const EdgeInsets.all(8), - boxAnimationDuration: - const Duration(milliseconds: 200), - itemAnimationDuration: - const Duration(milliseconds: 500), - hoverDuration: const Duration(milliseconds: 700), - child: _buildReactionsIcon(mainImage.value), - ); - }) - ], - ), - 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: [ - 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), - ], - ); + sizedBoxHeight(12.h), + commonDivider(), + sizedBoxHeight(12.h), + ]), + ), + ], + )); + } } Widget _buildReactionsPreviewIcon(String assetPath) { @@ -1168,7 +1375,154 @@ Widget containertile2({required String text}) { )); } -Widget popularTab() { +class PopularTab extends StatefulWidget { + const PopularTab({super.key}); + + @override + State createState() => _PopularTabState(); +} + +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); + } + } + + @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) { + 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() ?? + []; + for (var post in popularpostobj!.data) { + _initializeSelectedReaction(post.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); + } + } + List popularTabData = [ { "profileImg": "assets/images/png/Ellipse 43.png", @@ -1238,37 +1592,203 @@ Widget popularTab() { }, ]; - return Column( - children: [ - sizedBoxHeight(20.h), - Expanded( - child: ListView.builder( - shrinkWrap: true, - itemCount: popularTabData.length, - itemBuilder: (context, index) { - return Column( - children: [ - 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) - ], + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: popularfuture, + builder: (ctx, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator( + color: Colors.blue, + ), ); - }, - ), - ), - ], - ); + } + + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + _initializeData(); + return Stack(clipBehavior: Clip.none, children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill), + ), + ), + popularpostobj!.data.isEmpty + ? Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Column( + children: [ + Text( + "No Data Found", + style: TextStyle( + color: Colors.white, + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ) + ], + ), + ), + ]) + : Column( + children: [ + sizedBoxHeight(20.h), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: popularpostobj!.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()); + 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"], + description: popularData.caption ?? 'test', + 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(), + 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, + ), + ), + // 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) + ], + ); + }, + ), + ), + ], + ) + ]); + } + return Container(); + }); + } } class LatestTab extends StatefulWidget {