From d365d739316769c1a4a91a2c1c01aa9e96175d37 Mon Sep 17 00:00:00 2001 From: kishan Date: Fri, 16 Aug 2024 11:40:12 +0530 Subject: [PATCH] normal card and feed completee --- lib/Login/View/loginscreen.dart | 2 + lib/Login/ViewModel/LoginApi.dart | 3 + .../Community/ViewModel/getmethod.dart | 10 +- .../Community_HomePage/Community.dart | 412 ++++++++++-------- .../view_model/CountersHelper.dart | 15 +- lib/onboarding/SplashScreen.dart | 2 + 6 files changed, 254 insertions(+), 190 deletions(-) diff --git a/lib/Login/View/loginscreen.dart b/lib/Login/View/loginscreen.dart index 0d187e4..e9a2c36 100644 --- a/lib/Login/View/loginscreen.dart +++ b/lib/Login/View/loginscreen.dart @@ -7,6 +7,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Login/ViewModel/LoginApi.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Utils/Common/AppleOAuthService.dart'; import 'package:regroup/Utils/Common/CustomNextButton.dart'; import 'package:regroup/Utils/Common/CustomTextformfield.dart'; @@ -70,6 +71,7 @@ class _LoginScreenState extends State { snackPosition: SnackPosition.BOTTOM, ); // Get.toNamed(RouteName.mainscreen,arguments: 0); + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = diff --git a/lib/Login/ViewModel/LoginApi.dart b/lib/Login/ViewModel/LoginApi.dart index 80cf01b..7d0929c 100644 --- a/lib/Login/ViewModel/LoginApi.dart +++ b/lib/Login/ViewModel/LoginApi.dart @@ -4,6 +4,7 @@ import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; import 'package:regroup/Global.dart'; import 'package:regroup/Login/Model/LoginModel.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/onboarding/Signup/view_model/getUserprofile.dart'; import 'package:regroup/resources/routes/route_name.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -105,6 +106,7 @@ class LoginAPI { return ResponseData( "go-to-signin-via-oauth", ResponseStatus.SUCCESS); } else { + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = @@ -143,6 +145,7 @@ class LoginAPI { "go-to-signin-via-oauth", ResponseStatus.SUCCESS); } else { // Get.toNamed(RouteName.mainscreen); + await Communityallgetmethod().getLikeicons(); await Getuserdetails().Getuser().then((value) { if (getuserobj?.data?.userData?.isProfileUpdated == 0) { String? accountype = diff --git a/lib/Main_Screens/Community/ViewModel/getmethod.dart b/lib/Main_Screens/Community/ViewModel/getmethod.dart index 5733b1c..2a72663 100644 --- a/lib/Main_Screens/Community/ViewModel/getmethod.dart +++ b/lib/Main_Screens/Community/ViewModel/getmethod.dart @@ -5,20 +5,18 @@ import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Common/controller/data/network/network_api.dart'; import 'package:regroup/Main_Screens/Community/Model/fetchicons.dart'; -// FetchlikeIconsModel? likeiconsobj; +FetchlikeIconsModel? fetchlikeIconsModel; class Communityallgetmethod { - - Future> getLikeicons() async { + Future> getLikeicons() async { final response = await NetworkApiServices().getApi( ApiUrls.getLikeicons, // optionalpar: false ); if (response.status == ResponseStatus.SUCCESS) { - // likeiconsobj = FetchlikeIconsModel.fromJson(response.data); + fetchlikeIconsModel = FetchlikeIconsModel.fromJson(response.data); // log(likeiconsobj!.data.toString()); } return response; } - -} \ No newline at end of file +} diff --git a/lib/Main_Screens/Community_HomePage/Community.dart b/lib/Main_Screens/Community_HomePage/Community.dart index 955fea9..f550bbd 100644 --- a/lib/Main_Screens/Community_HomePage/Community.dart +++ b/lib/Main_Screens/Community_HomePage/Community.dart @@ -30,6 +30,7 @@ import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Main_Screens/Community/ViewModel/postmethod.dart'; import 'package:regroup/Main_Screens/Community_HomePage/PostDetailScreen/View/ReactionView.dart'; import 'package:regroup/Main_Screens/Community_HomePage/view_model/communitypostmethod.dart'; +import 'package:regroup/Utils/Common/ShimmerCommon.dart'; // import 'package:regroup/Feed%20Module/sidemenu/sidemenu.dart'; import 'package:regroup/Utils/Common/sized_box.dart'; import 'package:regroup/Utils/dialogs.dart'; @@ -217,39 +218,29 @@ class _FeedTabState extends State { super.initState(); } - Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _fetchIcons() { + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in commonobjmodel!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } - bool _isDataInitialized = true; - - Future setValues() async { - if (_isDataInitialized) { + setValues() { + if (mounted) { combinedList.clear(); combinedListGlobal.clear(); combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost); @@ -258,10 +249,7 @@ class _FeedTabState extends State { combinedListGlobal.addAll(combinedList); _setModel(); countersHelper.setListsPopular(); - - await _fetchIcons(); - - _isDataInitialized = false; + _fetchIcons(); } } @@ -335,92 +323,184 @@ class _FeedTabState extends State { @override Widget build(BuildContext context) { - return FutureBuilder( - future: feedfuture, - builder: (ctx, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); - } + return Obx( + () => countersHelper.updateFeedsPage.value + ? FutureBuilder( + future: FeedpostApi().getFeedPostApi(), + builder: (ctx, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: ShimmerCommon()); + } - if (snapshot.hasError) { - return Center( - child: Text( - '${snapshot.error} occurred', - style: TextStyle(fontSize: 18.spMin), - ), - ); - } + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - setValues(); - return Stack( - clipBehavior: Clip.none, - children: [ - Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/png/Ellipse 1496.png"), - fit: BoxFit.fill), - ), - ), - combinedList.isEmpty - ? Center( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "No posts are currently pinned", - style: TextStyle( - color: Colors.white, - fontSize: 16.sp, - fontWeight: FontWeight.w600), - ) - ], - ), - ) - : Column( - children: [ - sizedBoxHeight(20.h), - Expanded( - child: ListView.builder( - shrinkWrap: true, - itemCount: commonobjmodel!.data.length, - itemBuilder: (context, index) { - var timeAgo = ConvertServerDateToUserDate() - .convertServerDateToReadableFormate( - commonobjmodel!.data[index].createdAt - .toString()); - - return Column( - children: [ - NormalCardTile( - tags: _sortTags(index), - create_at: timeAgo ?? '1 hour', - commonObj: commonobjmodel!.data[index], - forWhichTab: 'feed', - reactions: _reactions, - selectedReactions: _selectedReactions, - currentIndex: index, - ), - sizedBoxHeight(20.h) - ], - ); - }, - ), + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + log("TRUE"); + setValues(); + return Stack( + clipBehavior: Clip.none, + children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + "assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill), ), - ], - ) - ], - ); - } - return Container(); - }, + ), + combinedList.isEmpty + ? Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "No posts are currently pinned", + style: TextStyle( + color: Colors.white, + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ) + ], + ), + ) + : Column( + children: [ + sizedBoxHeight(20.h), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: commonobjmodel!.data.length, + itemBuilder: (context, index) { + var timeAgo = ConvertServerDateToUserDate() + .convertServerDateToReadableFormate( + commonobjmodel! + .data[index].createdAt + .toString()); + + return Column( + children: [ + NormalCardTile( + tags: _sortTags(index), + create_at: timeAgo ?? '1 hour', + commonObj: + commonobjmodel!.data[index], + forWhichTab: 'feed', + reactions: _reactions, + selectedReactions: + _selectedReactions, + currentIndex: index, + ), + sizedBoxHeight(20.h) + ], + ); + }, + ), + ), + ], + ) + ], + ); + } + return Container(); + }, + ) + : FutureBuilder( + future: FeedpostApi().getFeedPostApi(), + builder: (ctx, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: ShimmerCommon()); + } + + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occurred', + style: TextStyle(fontSize: 18.spMin), + ), + ); + } + + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + log("FALSE"); + setValues(); + return Stack( + clipBehavior: Clip.none, + children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + "assets/images/png/Ellipse 1496.png"), + fit: BoxFit.fill), + ), + ), + combinedList.isEmpty + ? Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "No posts are currently pinned", + style: TextStyle( + color: Colors.white, + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ) + ], + ), + ) + : Column( + children: [ + sizedBoxHeight(20.h), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: commonobjmodel!.data.length, + itemBuilder: (context, index) { + var timeAgo = ConvertServerDateToUserDate() + .convertServerDateToReadableFormate( + commonobjmodel! + .data[index].createdAt + .toString()); + + return Column( + children: [ + NormalCardTile( + tags: _sortTags(index), + create_at: timeAgo ?? '1 hour', + commonObj: + commonobjmodel!.data[index], + forWhichTab: 'feed', + reactions: _reactions, + selectedReactions: + _selectedReactions, + currentIndex: index, + ), + sizedBoxHeight(20.h) + ], + ); + }, + ), + ), + ], + ) + ], + ); + } + return Container(); + }, + ), ); } } @@ -560,6 +640,8 @@ class _NormalCardTileState extends State { if (data.status == ResponseStatus.SUCCESS) { countersHelper.pinButtonPopular[widget.currentIndex] = !countersHelper.pinButtonPopular[widget.currentIndex]; + countersHelper.updateFeedsPage.value = + !countersHelper.updateFeedsPage.value; return utils.showToast(data.message); } else { return utils.showToast(data.message); @@ -573,6 +655,10 @@ class _NormalCardTileState extends State { @override Widget build(BuildContext context) { + var imgUrl = widget.commonObj.image! + .split( + "https://regroup.betadelivery.com/storage/app/public/uploads/post_image/") + .last; return commonGlassUI( width: double.infinity, height: 765.h, @@ -751,14 +837,16 @@ class _NormalCardTileState extends State { 'currentIndex': widget.currentIndex }); if (result) { - setState(() {}); + setState(() { + + }); } }, - child: Container( + child: SizedBox( height: 360, width: double.infinity, child: CachedNetworkImage( - // cacheKey: "1st", + cacheKey: imgUrl, imageUrl: widget.commonObj.image!, fit: BoxFit.cover, placeholder: (context, url) => const Center( @@ -1081,31 +1169,23 @@ class _PopularTabState extends State { } Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in popularpostobj!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } @@ -1195,11 +1275,7 @@ class _PopularTabState extends State { future: popularfuture, builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); + return const Center(child: ShimmerCommon()); } if (snapshot.hasError) { @@ -1301,32 +1377,24 @@ class _LatestTabState extends State { final CountersHelper countersHelper = Get.find(); int? likeIconIdnew; - Future _fetchIcons() async { - var response = await Communityallgetmethod().getLikeicons(); - if (response.status == ResponseStatus.SUCCESS) { - var responseData = response.data as Map; - FetchlikeIconsModel fetchlikeIconsModel = - FetchlikeIconsModel.fromJson(responseData); + _fetchIcons() { + _reactions = fetchlikeIconsModel!.data ?? []; + for (var post in commonobjmodel!.data) { + //Check if post as a like icon + if (post.likeIcon?.likeIcon?.id != null) { + likeIconIdnew = post.likeIcon!.likeIconsXid; - _reactions = fetchlikeIconsModel.data ?? []; - for (var post in latestpostobj!.data) { - //Check if post as a like icon - if (post.likeIcon != null) { - likeIconIdnew = post.likeIcon!.likeIconsXid; + final selectedReaction = _reactions.firstWhere( + (r) => r.id == likeIconIdnew, + orElse: () => _reactions.first, + ); - final selectedReaction = _reactions.firstWhere( - (r) => r.id == likeIconIdnew, - orElse: () => _reactions.first, - ); - - _selectedReactions[post.id!] = - selectedReaction; // Set selected reaction for this post - } else { - _selectedReactions[post.id!] = null; // No reaction selected - print('No reaction selected for post $postId'); - } + _selectedReactions[post.id!] = + selectedReaction; // Set selected reaction for this post + } else { + _selectedReactions[post.id!] = null; // No reaction selected + print('No reaction selected for post $postId'); } - setState(() {}); } } @@ -1336,7 +1404,7 @@ class _LatestTabState extends State { if (_isDataInitialized) { _setModel(); countersHelper.setListsPopular(); - await _fetchIcons(); + _fetchIcons(); _isDataInitialized = false; } @@ -1416,13 +1484,7 @@ class _LatestTabState extends State { future: futureGroup.future, builder: (ctx, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return - // ShimmerCommon(); - const Center( - child: CircularProgressIndicator( - color: Colors.blue, - ), - ); + return const Center(child: ShimmerCommon()); } if (snapshot.hasError) { diff --git a/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart index a142fcb..f2ff703 100644 --- a/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart +++ b/lib/Main_Screens/Community_HomePage/view_model/CountersHelper.dart @@ -4,20 +4,21 @@ import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart'; import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart'; List combinedListGlobal = []; - CommonDatumObjModel? commonobjmodel; +CommonDatumObjModel? commonobjmodel; + class CountersHelper extends GetxController { RxList likesCounterPopular = [].obs; RxList commentsCounterPopular = [].obs; RxList savePostCounterPopular = [].obs; RxList saveButtonPopular = [].obs; - RxList pinButtonPopular = [].obs; - - setListsPopular() { +List pinButtonPopular = []; + RxBool updateFeedsPage = false.obs; + setListsPopular() { likesCounterPopular.clear(); commentsCounterPopular.clear(); savePostCounterPopular.clear(); saveButtonPopular.clear(); - + pinButtonPopular.clear(); for (var i = 0; i < commonobjmodel!.data.length; i++) { likesCounterPopular.add(commonobjmodel?.data[i].likecount ?? 0); commentsCounterPopular @@ -52,8 +53,4 @@ class CountersHelper extends GetxController { savePostCounterFeed.add(latestpostobj!.data[i].totalSave ?? 0); } } - - - - } diff --git a/lib/onboarding/SplashScreen.dart b/lib/onboarding/SplashScreen.dart index 27aada9..8918a68 100644 --- a/lib/onboarding/SplashScreen.dart +++ b/lib/onboarding/SplashScreen.dart @@ -11,6 +11,7 @@ import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/base_manager.dart'; import 'package:regroup/Global.dart'; +import 'package:regroup/Main_Screens/Community/ViewModel/getmethod.dart'; import 'package:regroup/Main_Screens/ProfileTab/EditProfile/ViewModel/InterestApiList.dart'; import 'package:regroup/Utils/Common/NoInternet.dart'; import 'package:regroup/Utils/dialogs.dart'; @@ -46,6 +47,7 @@ class _SplashScreenState extends State { if (token == null || token!.isEmpty) { Get.toNamed(RouteName.onboarding1); } else { + await Communityallgetmethod().getLikeicons(); await InterestListApi().getinterestlistApi(); await Uploadata(deviceName); await Getuserdetails().Getuser().then((value) {