From ce2f6581962537f1418f206e6578eac93f9b6005 Mon Sep 17 00:00:00 2001 From: Dakshesh42 Date: Fri, 9 Aug 2024 15:47:34 +0530 Subject: [PATCH] postdetail pin api done --- .../View/PostDetailScreen.dart | 159 ++++++++++++------ 1 file changed, 107 insertions(+), 52 deletions(-) diff --git a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart index e78bcec..a949bc5 100644 --- a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart +++ b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart @@ -1,6 +1,5 @@ import 'dart:developer'; -import 'package:comment_tree/comment_tree.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @@ -16,11 +15,15 @@ import 'package:regroup/Common/ConvertServerDateToUserDate.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Global.dart'; import 'package:regroup/Main_Screens/Community/Model/fetchicons.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/Model/PostDetailModel.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/Utils/Common/CommonAppbar.dart'; import 'package:regroup/Utils/Common/CustomTextformfield.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; @@ -28,6 +31,7 @@ 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}); @@ -147,6 +151,48 @@ class _PostDetailsScreenState extends State { } } +//savePost + + saveunsavepost(int postid) async { + // utils.loader(); + Map updata = { + "manage_posts_xid": postid, + }; + 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); + } + } + +//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(); + LatespostApi().getLatestPostApi().then((value) { + _initializeData(); + setState(() {}); + }); + return utils.showToast(data.message); + } else { + // Get.back(); + return utils.showToast(data.message); + } + } + List hideReplies = []; FutureGroup futureGroup = FutureGroup(); final FocusNode _focusNode = FocusNode(); @@ -295,6 +341,10 @@ class _PostDetailsScreenState extends State { 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( @@ -309,7 +359,7 @@ class _PostDetailsScreenState extends State { profileImg: postDetailData.iamPrincipal!.profilePhoto ?? '', title: postDetailData.iamPrincipal!.fullName ?? "", mainImg: postDetailData.image ?? "", - containerTitle: [] ?? [], + tags: tags, description: postDetailData.caption ?? 'test', create_at: timeAgo ?? '1 hour', total_comments: postDetailData.totalCommentCount.toString() ?? '20', @@ -325,9 +375,14 @@ class _PostDetailsScreenState extends State { // }); }, onSaveIconTap: () async { - // await saveunsavepost(popularData.id!); + await saveunsavepost(postDetailData.id!); }, isISaved: postDetailData.isISaved, + PinPopupTap: () async { + int pinPospostid = postDetailData.iamPrincipal!.id!; + await pinunpinUser(pinPospostid); + }, + isUserPinned: postDetailData.iamPrincipal!.isUserPinned, onReactionChangedLike: (reaction) async { if (selectedReaction != null && reaction?.value == selectedReaction.id.toString()) { @@ -875,7 +930,7 @@ class PostCardTile extends StatefulWidget { 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; @@ -883,7 +938,10 @@ class PostCardTile extends StatefulWidget { final String? create_at; final String? postId; final void Function()? onSaveIconTap; + final void Function()? PinPopupTap; final bool? isISaved; + final bool? isUserPinned; + // final dynamic commonpostobj; final void Function(Reaction?) onReactionChangedLike; final List?> reactionsLike; @@ -891,28 +949,31 @@ class PostCardTile extends StatefulWidget { 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.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, - }) : super(key: key); + const PostCardTile( + {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.PinPopupTap, + this.isISaved, + this.isUserPinned}) + : super(key: key); @override _PostCardTileState createState() => _PostCardTileState(); @@ -1032,14 +1093,16 @@ class _PostCardTileState extends State { ), const PopupMenuDivider(), PopupMenuItem( - onTap: () {}, + onTap: widget.PinPopupTap, child: Padding( padding: EdgeInsets.symmetric(horizontal: 12.w), child: Row( children: [ Text( - 'Pin', + widget.isUserPinned == true + ? 'Unpin' + : 'Pin', style: TextStyle( fontSize: 16.sp, color: Colors.white, @@ -1117,20 +1180,28 @@ class _PostCardTileState extends State { child: ListView.builder( scrollDirection: Axis.horizontal, shrinkWrap: true, - itemCount: widget.containerTitle.length, + itemCount: widget.tags.length, itemBuilder: (context, index) { + var manageTag = widget.tags[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, - // } + 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: ("#${widget.containerTitle[index]}"))), + child: + containertile2(text: ('#${manageTag.name}'))), ); }, ), @@ -1298,22 +1369,6 @@ class _PostCardTileState extends State { text11w400_FCFCFC('Like'), ], ), - 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: [ GestureDetector(