diff --git a/lib/Common/controller/NormalPostCard.dart b/lib/Common/controller/NormalPostCard.dart index 3b4d591..91b7347 100644 --- a/lib/Common/controller/NormalPostCard.dart +++ b/lib/Common/controller/NormalPostCard.dart @@ -27,7 +27,7 @@ class NormalCardTile extends StatefulWidget { List reactions; Map selectedReactions; bool? coachbool; - + bool showCommentButton; int currentIndex; NormalCardTile( {Key? key, @@ -38,6 +38,7 @@ class NormalCardTile extends StatefulWidget { required this.reactions, required this.selectedReactions, required this.currentIndex, + this.showCommentButton = true, this.coachbool}) : super(key: key); @@ -176,7 +177,7 @@ class _NormalCardTileState extends State { .last; return ConstrainedBox( - constraints: BoxConstraints(minHeight: 820.h), + constraints: BoxConstraints(minHeight: Get.width < 400 ? 750 : 700), child: commonGlassUI( width: double.infinity, height: 600.h, @@ -370,19 +371,21 @@ class _NormalCardTileState extends State { sizedBoxHeight(20.h), GestureDetector( onTap: () async { - bool result = await Get.toNamed(RouteName.postdetailsScreen, - arguments: { - 'postId': widget.commonObj.id, - 'tagsList': widget.tags, - 'created_at': widget.createAt, - 'commonObj': widget.commonObj, - 'fromWhichTab': widget.forWhichTab, - 'reactions': widget.reactions, - 'selectedReactions': widget.selectedReactions, - 'currentIndex': widget.currentIndex - }); - if (result) { - setState(() {}); + if (widget.showCommentButton) { + bool result = await Get.toNamed(RouteName.postdetailsScreen, + arguments: { + 'postId': widget.commonObj.id, + 'tagsList': widget.tags, + 'created_at': widget.createAt, + 'commonObj': widget.commonObj, + 'fromWhichTab': widget.forWhichTab, + 'reactions': widget.reactions, + 'selectedReactions': widget.selectedReactions, + 'currentIndex': widget.currentIndex + }); + if (result) { + setState(() {}); + } } }, child: SizedBox( @@ -405,6 +408,7 @@ class _NormalCardTileState extends State { child: Column(children: [ SizedBox( height: 30.h, + width: double.infinity, child: ListView.builder( scrollDirection: Axis.horizontal, shrinkWrap: true, @@ -502,8 +506,11 @@ class _NormalCardTileState extends State { ), ), sizedBoxWidth(12.w), - text14w400_FCFCFC( - widget.commonObj.totalCommentCount.toString()), + Obx( + () => text14w400_FCFCFC(countersHelper + .commentsCounterPopular[widget.currentIndex] + .toString()), + ), sizedBoxWidth(20.w), commonContainer( width: 30.w, @@ -607,36 +614,39 @@ class _NormalCardTileState extends State { text11w400_FCFCFC('Like'), ], ), - GestureDetector( - onTap: () async { - bool result = await Get.toNamed( - RouteName.postdetailsScreen, - arguments: { - 'postId': widget.commonObj.id, - 'tagsList': widget.tags, - 'created_at': widget.createAt, - 'commonObj': widget.commonObj, - 'fromWhichTab': widget.forWhichTab, - 'reactions': widget.reactions, - 'selectedReactions': widget.selectedReactions, - 'currentIndex': widget.currentIndex - }); - if (result) { - setState(() {}); - } - }, - child: Column( - children: [ - Image.asset( - 'assets/images/png/Frame 1000004088.png', - height: 19.h, - width: 19.w, - ), - sizedBoxHeight(8.h), - text11w400_FCFCFC('Comment') - ], - ), - ), + widget.showCommentButton + ? GestureDetector( + onTap: () async { + bool result = await Get.toNamed( + RouteName.postdetailsScreen, + arguments: { + 'postId': widget.commonObj.id, + 'tagsList': widget.tags, + 'created_at': widget.createAt, + 'commonObj': widget.commonObj, + 'fromWhichTab': widget.forWhichTab, + 'reactions': widget.reactions, + 'selectedReactions': + widget.selectedReactions, + 'currentIndex': widget.currentIndex + }); + if (result) { + setState(() {}); + } + }, + child: Column( + children: [ + Image.asset( + 'assets/images/png/Frame 1000004088.png', + height: 19.h, + width: 19.w, + ), + sizedBoxHeight(8.h), + text11w400_FCFCFC('Comment') + ], + ), + ) + : SizedBox(), Obx( () => Column( //here diff --git a/lib/Main_Screens/Community_HomePage/Community.dart b/lib/Main_Screens/Community_HomePage/Community.dart index 029afc3..8425ef5 100644 --- a/lib/Main_Screens/Community_HomePage/Community.dart +++ b/lib/Main_Screens/Community_HomePage/Community.dart @@ -500,15 +500,12 @@ class PopularTab extends StatefulWidget { } class _PopularTabState extends State { - late Future popularfuture; List _reactions = []; final Map _selectedReactions = {}; final CountersHelper countersHelper = Get.find(); int? likeIconIdnew; @override void initState() { - popularfuture = PopularpostApi().getPopularPostApi(); - super.initState(); } @@ -541,6 +538,12 @@ class _PopularTabState extends State { } } + Future _initialize() async { + //api call here + await PopularpostApi().getPopularPostApi(); + await setValues(); + } + _sortTags(index) { var tags = commonobjmodel!.data[index].attachTags .where((tag) => tag.manageTag?.name?.isNotEmpty ?? false) @@ -612,7 +615,7 @@ class _PopularTabState extends State { @override Widget build(BuildContext context) { return FutureBuilder( - future: popularfuture, + future: _initialize(), builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: ShimmerCommon()); @@ -627,9 +630,7 @@ class _PopularTabState extends State { ); } - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - setValues(); + if (snapshot.connectionState == ConnectionState.done) { return Stack(clipBehavior: Clip.none, children: [ Container( decoration: const BoxDecoration( @@ -703,12 +704,8 @@ class LatestTab extends StatefulWidget { } class _LatestTabState extends State { - late Future latestfuture; - @override void initState() { - latestfuture = LatespostApi().getLatestPostApi(); - super.initState(); } @@ -818,10 +815,16 @@ class _LatestTabState extends State { .toList()); } + Future _initialize() async { + //api call here + await LatespostApi().getLatestPostApi(); + await setValues(); + } + @override Widget build(BuildContext context) { return FutureBuilder( - future: latestfuture, + future: _initialize(), builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: ShimmerCommon()); @@ -836,9 +839,7 @@ class _LatestTabState extends State { ); } - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - setValues(); + if (snapshot.connectionState == ConnectionState.done) { return Stack( clipBehavior: Clip.none, children: [ @@ -849,7 +850,7 @@ class _LatestTabState extends State { fit: BoxFit.fill), ), ), - latestpostobj!.data.isEmpty + commonobjmodel!.data.isEmpty ? Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart index 98376ff..9b58250 100644 --- a/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart +++ b/lib/Main_Screens/Community_HomePage/PostDetailScreen/View/PostDetailScreen.dart @@ -1,5 +1,3 @@ - - import 'package:flutter/material.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -13,9 +11,11 @@ import 'package:regroup/Main_Screens/Community/Model/fetchicons.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/CountersHelper.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/ShimmerCommon.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; import 'package:regroup/Utils/dialogs.dart'; import 'package:regroup/Utils/texts.dart'; @@ -50,7 +50,7 @@ class _PostDetailsScreenState extends State { final FocusNode _focusNode = FocusNode(); final TextEditingController _controllerComments = TextEditingController(); final CommentsHelper _commentsHelper = Get.put(CommentsHelper()); - + final CountersHelper countersHelper = Get.find(); String? mainpostid; List? tags; String? create_at; @@ -70,7 +70,6 @@ class _PostDetailsScreenState extends State { reactions = Get.arguments['reactions']; selectedReactions = Get.arguments['selectedReactions']; currentIndex = Get.arguments['currentIndex']; - futureGroup.add(CommentsRepository().getAllComments(mainpostid)); futureGroup.add(PostDetailApi().getPostDetail(mainpostid)); futureGroup.close(); @@ -102,6 +101,7 @@ class _PostDetailsScreenState extends State { }; final result = await CommentsRepository().postComments(updata); if (result.status == ResponseStatus.SUCCESS) { + countersHelper.commentsCounterPopular[currentIndex!]++; CommentsRepository() .getAllComments(mainpostid) .then((value) => setState(() { @@ -150,6 +150,7 @@ class _PostDetailsScreenState extends State { var updata = {"id": commentId}; final result = await CommentsRepository().deleteComments(updata); if (result.status == ResponseStatus.SUCCESS) { + countersHelper.commentsCounterPopular[currentIndex!]--; CommentsRepository() .getAllComments(mainpostid) .then((value) => setState(() { @@ -193,11 +194,7 @@ class _PostDetailsScreenState extends State { future: futureGroup.future, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); + return const Center(child: ShimmerCommon()); } else if (snapshot.hasError) { return Center( child: Text( @@ -239,189 +236,9 @@ class _PostDetailsScreenState extends State { reactions: reactions!, selectedReactions: selectedReactions!, currentIndex: currentIndex!, + showCommentButton: false, ), - // ListView.builder( - // physics: const NeverScrollableScrollPhysics(), - // shrinkWrap: true, - // itemCount: nestedComments!.data.length, - // itemBuilder: (context, index) { - // List _repliedCommentsSorted = _setComments(index); - // return Container( - // padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16), - // child: CommentTreeWidget( - // Comment( - // avatar: - // nestedComments!.data[index].userDetail!.profilePhoto, - // userName: nestedComments!.data[index].userDetail!.userName, - // content: nestedComments!.data[index].comment), - // [], - // // _repliedCommentsSorted.isNotEmpty ? _repliedCommentsSorted : [], - // treeThemeData: const TreeThemeData( - // lineColor: Color(0xFFD90B2E), lineWidth: 2.5), - // avatarRoot: (context, data) => PreferredSize( - // preferredSize: const Size.fromRadius(18), - // child: CircleAvatar( - // radius: 18, - // backgroundColor: Colors.grey, - // backgroundImage: NetworkImage( - // data.avatar ?? - // "https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png?20150327203541", - // ), - // ), - // ), - // avatarChild: (context, data) => PreferredSize( - // preferredSize: const Size.fromRadius(12), - // child: CircleAvatar( - // radius: 12, - // backgroundColor: Colors.grey, - // backgroundImage: NetworkImage( - // data.avatar ?? - // "https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png?20150327203541", - // ), - // ), - // ), - // contentChild: (context, data) { - // return data.userName! == "Ram" && _hideReplies[index] - // ? GestureDetector( - // onTap: () { - // setState(() { - // _hideReplies[index] = false; - // }); - // }, - // child: Container( - // child: const Text( - // "View more", - // style: TextStyle(color: Colors.white), - // ), - // ), - // ) - // : Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Container( - // padding: const EdgeInsets.symmetric( - // vertical: 8, horizontal: 8), - // decoration: BoxDecoration( - // color: Colors.grey[100], - // borderRadius: BorderRadius.circular(12)), - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Text( - // '${data.userName}', - // style: Theme.of(context) - // .textTheme - // .bodySmall - // ?.copyWith( - // fontWeight: FontWeight.w600, - // color: Colors.black), - // ), - // const SizedBox( - // height: 4, - // ), - // Text( - // '${data.content}', - // style: Theme.of(context) - // .textTheme - // .bodySmall - // ?.copyWith( - // fontWeight: FontWeight.w300, - // color: Colors.black), - // ), - // ], - // ), - // ), - // DefaultTextStyle( - // style: Theme.of(context) - // .textTheme - // .bodySmall! - // .copyWith( - // color: Colors.grey[700], - // fontWeight: FontWeight.bold), - // child: const Padding( - // padding: EdgeInsets.only(top: 4), - // child: Row( - // children: [ - // SizedBox( - // width: 8, - // ), - // Text('Like'), - // SizedBox( - // width: 24, - // ), - // Text('Reply'), - // ], - // ), - // ), - // ) - // ], - // ); - // }, - // contentRoot: (context, data) { - // return Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Container( - // padding: const EdgeInsets.symmetric( - // vertical: 8, horizontal: 8), - // decoration: BoxDecoration( - // color: Colors.grey[100], - // borderRadius: BorderRadius.circular(12)), - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Text( - // 'dangngocduc', - // style: Theme.of(context) - // .textTheme - // .bodySmall! - // .copyWith( - // fontWeight: FontWeight.w600, - // color: Colors.black), - // ), - // const SizedBox( - // height: 4, - // ), - // Text( - // '${data.content}', - // style: Theme.of(context) - // .textTheme - // .bodySmall! - // .copyWith( - // fontWeight: FontWeight.w300, - // color: Colors.black), - // ), - // ], - // ), - // ), - // DefaultTextStyle( - // style: Theme.of(context).textTheme.bodySmall!.copyWith( - // color: Colors.grey[700], - // fontWeight: FontWeight.bold), - // child: const Padding( - // padding: EdgeInsets.only(top: 4), - // child: Row( - // children: [ - // SizedBox( - // width: 8, - // ), - // Text('Like'), - // SizedBox( - // width: 24, - // ), - // Text('Reply'), - // ], - // ), - // ), - // ) - // ], - // ); - // }, - // ), - // ); - // }, - // ), sizedBoxHeight(35.h), ListView.builder( diff --git a/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart b/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart index 37959a7..3150ac1 100644 --- a/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart +++ b/lib/Main_Screens/Community_HomePage/TagsdDetailScreen.dart @@ -245,6 +245,7 @@ class _PopularTabState extends State { await setValues(); } + @override Widget build(BuildContext context) { return FutureBuilder(