Merge pull request #128 from WDI-Ideas/performanceimprove

normal card and feed completee
This commit is contained in:
Kishan Bhuta
2024-08-16 11:42:06 +05:30
committed by GitHub
6 changed files with 254 additions and 190 deletions

View File

@@ -8,6 +8,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/CustomTextformfield.dart';
import 'package:regroup/Utils/Common/googleOAuthService.dart';
@@ -69,6 +70,7 @@ class _LoginScreenState extends State<LoginScreen> {
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 =

View File

@@ -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<dynamic>(
"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 =

View File

@@ -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<ResponseData<dynamic>> getLikeicons() async {
Future<ResponseData<dynamic>> 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;
}
}
}

View File

@@ -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<FeedTab> {
super.initState();
}
Future<void> _fetchIcons() async {
var response = await Communityallgetmethod().getLikeicons();
if (response.status == ResponseStatus.SUCCESS) {
var responseData = response.data as Map<String, dynamic>;
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<void> setValues() async {
if (_isDataInitialized) {
setValues() {
if (mounted) {
combinedList.clear();
combinedListGlobal.clear();
combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost);
@@ -258,10 +249,7 @@ class _FeedTabState extends State<FeedTab> {
combinedListGlobal.addAll(combinedList);
_setModel();
countersHelper.setListsPopular();
await _fetchIcons();
_isDataInitialized = false;
_fetchIcons();
}
}
@@ -335,92 +323,184 @@ class _FeedTabState extends State<FeedTab> {
@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<NormalCardTile> {
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<NormalCardTile> {
@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<NormalCardTile> {
'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<PopularTab> {
}
Future<void> _fetchIcons() async {
var response = await Communityallgetmethod().getLikeicons();
if (response.status == ResponseStatus.SUCCESS) {
var responseData = response.data as Map<String, dynamic>;
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<PopularTab> {
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<LatestTab> {
final CountersHelper countersHelper = Get.find<CountersHelper>();
int? likeIconIdnew;
Future<void> _fetchIcons() async {
var response = await Communityallgetmethod().getLikeicons();
if (response.status == ResponseStatus.SUCCESS) {
var responseData = response.data as Map<String, dynamic>;
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<LatestTab> {
if (_isDataInitialized) {
_setModel();
countersHelper.setListsPopular();
await _fetchIcons();
_fetchIcons();
_isDataInitialized = false;
}
@@ -1416,13 +1484,7 @@ class _LatestTabState extends State<LatestTab> {
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) {

View File

@@ -4,20 +4,21 @@ import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart';
import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart';
List<PinnedPost> combinedListGlobal = [];
CommonDatumObjModel? commonobjmodel;
CommonDatumObjModel? commonobjmodel;
class CountersHelper extends GetxController {
RxList<int> likesCounterPopular = <int>[].obs;
RxList<int> commentsCounterPopular = <int>[].obs;
RxList<int> savePostCounterPopular = <int>[].obs;
RxList<bool> saveButtonPopular = <bool>[].obs;
RxList<bool> pinButtonPopular = <bool>[].obs;
setListsPopular() {
List<bool> pinButtonPopular = <bool>[];
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);
}
}
}

View File

@@ -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<SplashScreen> {
if (token == null || token!.isEmpty) {
Get.toNamed(RouteName.onboarding1);
} else {
await Communityallgetmethod().getLikeicons();
await InterestListApi().getinterestlistApi();
await Uploadata(deviceName);
await Getuserdetails().Getuser().then((value) {