common card added

This commit is contained in:
kishan
2024-08-11 19:22:25 +05:30
parent c8a8a73070
commit 39cbcb4845
4 changed files with 280 additions and 613 deletions

View File

@@ -2,7 +2,7 @@ class FetchlikeIconsModel {
String? status;
int? statusCode;
String? message;
List<Data>? data;
List<ReactionData>? data;
FetchlikeIconsModel({this.status, this.statusCode, this.message, this.data});
@@ -11,18 +11,18 @@ class FetchlikeIconsModel {
statusCode = json['status_code'];
message = json['message'];
if (json['data'] != null) {
data = <Data>[];
data = <ReactionData>[];
json['data'].forEach((v) {
data!.add(new Data.fromJson(v));
data!.add(ReactionData.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['status'] = this.status;
data['status_code'] = this.statusCode;
data['message'] = this.message;
final Map<String, dynamic> data = <String, dynamic>{};
data['status'] = status;
data['status_code'] = statusCode;
data['message'] = message;
if (this.data != null) {
data['data'] = this.data!.map((v) => v.toJson()).toList();
}
@@ -30,35 +30,35 @@ class FetchlikeIconsModel {
}
}
class Data {
class ReactionData {
int? id;
String? image;
String image = "";
Data({this.id, this.image});
ReactionData({this.id, required this.image});
Data.fromJson(Map<String, dynamic> json) {
ReactionData.fromJson(Map<String, dynamic> json) {
id = json['id'];
image = json['image'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['image'] = this.image;
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['image'] = image;
return data;
}
}
class ReactionData {
final int id;
final String image;
// class ReactionData {
// final int id;
// final String image;
ReactionData({required this.id, required this.image});
// ReactionData({required this.id, required this.image});
factory ReactionData.fromJson(Map<String, dynamic> json) {
return ReactionData(
id: json['id'],
image: json['image'],
);
}
}
// factory ReactionData.fromJson(Map<String, dynamic> json) {
// return ReactionData(
// id: json['id'],
// image: json['image'],
// );
// }
// }

View File

@@ -5,7 +5,7 @@ import 'package:regroup/Main_Screens/Community/Model/PopularPostModel.dart';
PopularpostModel? popularpostobj;
class PopularpostApi {
class PopularpostApi{
PopularpostApi();
Future<ResponseData<dynamic>> getPopularPostApi() async {

View File

@@ -435,7 +435,7 @@ class _FeedTabState extends State<FeedTab> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"No Data Found",
"No posts are currently pinned",
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
@@ -1782,49 +1782,20 @@ class _FeedTabState extends State<FeedTab> {
}
class NormalCardTile extends StatefulWidget {
final String profileImg;
final String title;
final String mainImg;
final String description;
// final List<String> containerTitle;
final List<ManageTagPopular> tags;
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<String>?) onReactionChangedLike;
final List<Reaction<String>?> reactionsLike;
final Reaction<String>? selectedReactionLike;
final Widget? likePopupWidget;
final void Function()? mainImagetap;
const NormalCardTile({
List<ManageTagPopular> tags;
String? create_at;
Datum commonObj;
String forWhichTab;
List<ReactionData> reactions;
Map<int, ReactionData?> selectedReactions;
NormalCardTile({
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.isISaved,
required this.forWhichTab,
required this.commonObj,
required this.reactions,
required this.selectedReactions,
}) : super(key: key);
@override
@@ -1834,137 +1805,130 @@ class NormalCardTile extends StatefulWidget {
class _NormalCardTileState extends State<NormalCardTile> {
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';
} 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';
_handleReactionChange(Reaction<String>? reaction) async {
if (widget.selectedReactions[widget.commonObj.id] != null &&
reaction?.value ==
widget.selectedReactions[widget.commonObj.id]!.id.toString() ||
reaction?.value == null) {
// User tapped on the currently selected reaction, so remove it
//api call for dislike
await LikeUploaddata(
widget.selectedReactions[widget.commonObj.id]?.id,
widget.commonObj.id!,
);
setState(() {
widget.selectedReactions[widget.commonObj.id!] = null;
});
} else {
// User selected a new reaction
var newSelectedReaction = widget.reactions.firstWhere(
(r) => r.id.toString() == reaction?.value,
orElse: () => widget.reactions.first, // Default reaction if not found
);
await _handleReactionChangeApiCall(
newSelectedReaction, widget.commonObj.id!);
}
}
// List<ReactionData> _reactions = [];
// Map<int, ReactionData?> _selectedReactions = {};
Future<void> _handleReactionChangeApiCall(
ReactionData? reaction, int postId) async {
setState(() {
widget.selectedReactions[postId] =
reaction; // Set the selected reaction for this post
});
// Future<void> _initializeData() async {
// await _fetchIcons();
await LikeUploaddata(
reaction?.id,
postId,
);
}
// 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
// }
// }
LikeUploaddata(int? likeIconId, int? postid) async {
Map<String, dynamic> updata = {
"manage_posts_xid": postid,
"like_icons_xid": likeIconId ?? '',
};
final data = await CommunitypostMethod().postLikepost(updata);
if (data.status == ResponseStatus.SUCCESS) {
await _refreshData();
return utils.showToast(data.message);
} else {
return utils.showToast(data.message);
}
}
// 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);
_refreshData() async {
switch (widget.forWhichTab) {
case 'feed':
await FeedpostApi().getFeedPostApi();
break;
case 'popular':
await PopularpostApi().getPopularPostApi();
break;
case 'latest':
await LatespostApi().getLatestPostApi();
break;
default:
print('Error Occured');
}
}
// setState(() {
// _reactions = fetchlikeIconsModel.data
// ?.map((data) => ReactionData(
// id: data.id!,
// image: data.image!,
// ))
// .toList() ??
// [];
// for (var post in latestpostobj!.data) {
// _initializeSelectedReaction(post.id!);
// }
// });
// }
// }
void updateImage(String reaction) {
switch (reaction) {
case 'like':
mainImage.value = 'assets/images/png/f7_hand-thumbsup.png';
break;
case 'heart':
mainImage.value = 'assets/images/png/heart 2.png';
break;
case 'party':
mainImage.value = 'assets/images/png/party-popper 2.png';
break;
default:
// Handle any other cases or do nothing
break;
}
}
// int? likeIconIdnew;
saveunsavepost(int popularpostid) async {
// utils.loader();
Map<String, dynamic> updata = {
"manage_posts_xid": popularpostid,
};
final data = await Communitypostmethod().postUserSave(updata);
if (data.status == ResponseStatus.SUCCESS) {
// PopularpostApi().getPopularPostApi().then((value) {
// _initializeData();
// setState(() {});
// });
// 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,
// );
return utils.showToast(data.message);
} else {
return utils.showToast(data.message);
}
}
// 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<void> _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<String, dynamic> 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();
// }
pinunpinUser(int userid) async {
Map<String, dynamic> updata = {
"pin_iam_principal_xid": userid,
};
final data = await SidebarTags().postUserpin(updata);
if (data.status == ResponseStatus.SUCCESS) {
_refreshData();
return utils.showToast(data.message);
} else {
return utils.showToast(data.message);
}
}
@override
Widget build(BuildContext context) {
return commonGlassUI(
width: double.infinity,
height: 760.h,
height: 765.h,
mainOpacity: 1,
borderRadius: BorderRadius.circular(1),
customWidget: Column(
@@ -1976,14 +1940,16 @@ class _NormalCardTileState extends State<NormalCardTile> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
foregroundImage: NetworkImage(widget.profileImg),
foregroundImage: NetworkImage(
widget.commonObj.iamPrincipal!.profilePhoto!),
radius: 25.r,
),
sizedBoxWidth(12.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16w400_FCFCFC(widget.title),
text16w400_FCFCFC(
widget.commonObj.iamPrincipal!.fullName ?? "Regroup"),
sizedBoxHeight(5.h),
Row(
children: [
@@ -1993,7 +1959,8 @@ class _NormalCardTileState extends State<NormalCardTile> {
width: 14.w,
),
sizedBoxWidth(7.w),
text12w400_FCFCFC(widget.community_name),
text12w400_FCFCFC(
widget.commonObj.community!.communityName ?? ""),
sizedBoxWidth(7.w),
Icon(
Icons.circle,
@@ -2067,7 +2034,9 @@ class _NormalCardTileState extends State<NormalCardTile> {
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
onTap: () {
pinunpinUser(widget.commonObj.iamPrincipal!.id!);
},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12.w),
child: Row(
@@ -2104,7 +2073,11 @@ class _NormalCardTileState extends State<NormalCardTile> {
),
sizedBoxHeight(20.h),
GestureDetector(
onTap: widget.mainImagetap,
onTap: () {
Get.toNamed(RouteName.postdetailsScreen, arguments: {
'postId': widget.commonObj.id,
});
},
child: Container(
height: 360,
width: double.infinity,
@@ -2112,7 +2085,7 @@ class _NormalCardTileState extends State<NormalCardTile> {
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
widget.mainImg,
widget.commonObj.image!,
),
),
),
@@ -2172,18 +2145,18 @@ class _NormalCardTileState extends State<NormalCardTile> {
height: 80.h,
width: double.infinity,
child: SingleChildScrollView(
child: text16w400_FCFCFC(widget.description)),
child: text16w400_FCFCFC(widget.commonObj.caption ?? "")),
),
sizedBoxHeight(20.h),
Row(children: [
InkWell(
onTap: () {
Get.toNamed(RouteName.reactionview, arguments: {
'postId': widget.postId,
'postId': widget.commonObj.id,
});
},
child: stackReaction(
number: widget.total_likes,
number: widget.commonObj.totalReactionCount.toString(),
containerImages: [
'assets/images/png/f7_hand-thumbsup.png',
'assets/images/png/heart 2.png',
@@ -2208,7 +2181,8 @@ class _NormalCardTileState extends State<NormalCardTile> {
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC(widget.total_comments),
text14w400_FCFCFC(
widget.commonObj.totalCommentCount.toString()),
sizedBoxWidth(20.w),
commonContainer(
width: 30.w,
@@ -2227,7 +2201,7 @@ class _NormalCardTileState extends State<NormalCardTile> {
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC(widget.total_save),
text14w400_FCFCFC(widget.commonObj.totalSave.toString()),
]),
sizedBoxHeight(12.h),
commonDivider(),
@@ -2239,68 +2213,45 @@ class _NormalCardTileState extends State<NormalCardTile> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
ReactionButton<String>(
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<String>(
// 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<String>(
// value:
// _selectedReactions[postId]!.id.toString(),
// icon: Image.network(
// _selectedReactions[postId]!.image,
// width: 24,
// height: 24,
// fit: BoxFit.cover,
// ),
// )
// : Reaction<String>(
// value: '',
// icon: Image.asset(
// 'assets/images/png/uiw_like-o.png',
// width: 24,
// height: 24,
// fit: BoxFit.cover,
// ),
// ),
onReactionChanged: (reaction) async {
_handleReactionChange(reaction);
},
reactions: widget.reactions
.map((reaction) => Reaction<String>(
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
.selectedReactions[widget.commonObj.id] !=
null
? Reaction<String>(
value: widget
.selectedReactions[widget.commonObj.id]!
.id
.toString(),
icon: Image.network(
widget
.selectedReactions[widget.commonObj.id]!
.image,
width: 24,
height: 24,
fit: BoxFit.cover,
),
)
: null,
boxColor: Colors.white,
boxElevation: 9,
boxRadius: 30,
itemsSpacing: 8,
itemScale: 0.4,
itemsSpacing: 20,
itemScale: 0.3,
itemSize: const Size(30, 30),
boxPadding: const EdgeInsets.all(8),
boxAnimationDuration:
@@ -2308,31 +2259,33 @@ class _NormalCardTileState extends State<NormalCardTile> {
itemAnimationDuration:
const Duration(milliseconds: 500),
hoverDuration: const Duration(milliseconds: 700),
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,
// ),
child: widget
.selectedReactions[widget.commonObj.id] !=
null
? Image.network(
widget.selectedReactions[widget.commonObj.id]!
.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('Like'),
],
),
GestureDetector(
onTap: widget.mainImagetap,
// onTap: () {
// Get.toNamed(RouteName.postdetailsScreen, );
// },
onTap: () {
Get.toNamed(RouteName.postdetailsScreen, arguments: {
"PostId": widget.commonObj.id.toString()
});
},
child: Column(
children: [
Image.asset(
@@ -2348,8 +2301,9 @@ class _NormalCardTileState extends State<NormalCardTile> {
Column(
children: [
GestureDetector(
onTap: widget.onSaveIconTap,
child: widget.isISaved == true
onTap: () async =>
await saveunsavepost(widget.commonObj.id!),
child: widget.commonObj.isISaved == true
? Image.asset(
'assets/images/png/postSaved.png',
height: 19.h,
@@ -2438,52 +2392,16 @@ class PopularTab extends StatefulWidget {
class _PopularTabState extends State<PopularTab> {
late Future popularfuture;
saveunsavepost(int popularpostid) async {
// utils.loader();
Map<String, dynamic> 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);
}
}
List<ReactionData> _reactions = [];
Map<int, ReactionData?> _selectedReactions = {};
@override
void initState() {
popularfuture = PopularpostApi().getPopularPostApi();
// _initializeData();
// TODO: implement initState
super.initState();
}
//reacttionlikelogic
List<ReactionData> _reactions = [];
Map<int, ReactionData?> _selectedReactions = {};
Future<void> _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
}
}
int? likeIconIdnew;
Future<void> _fetchIcons() async {
var response = await Communityallgetmethod().getLikeicons();
if (response.status == ResponseStatus.SUCCESS) {
@@ -2491,178 +2409,46 @@ class _PopularTabState extends State<PopularTab> {
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!);
_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,
);
_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');
}
});
}
}
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<void> _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
});
setState(() {});
}
}
LikeUploaddata(int? likeIconId, int? postid) async {
// utils.loader();
Map<String, dynamic> 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",
"title": "Edward Hackket",
"mainImg": "assets/images/png/Rectangle 24.png",
"containerTitle": ['Cycle', 'Marathon', 'Events', 'Marathon', 'Events'],
"desciption": "",
"create_at": '1 hour',
"total_comments": 20,
"total_likes": 20,
"total_save": 10,
"community_name": 'text',
},
{
"profileImg": "assets/images/png/Ellipse 52.png",
"title": "Ryan Dorwat",
"mainImg": "assets/images/png/Rectangle 25.png",
"containerTitle": [
'Football',
'Teams player',
'Events',
'Marathon',
'Events'
],
"desciption": "",
"create_at": '1 hour',
"total_comments": 20,
"total_likes": 20,
"total_save": 10,
"community_name": 'text',
},
{
"profileImg": "assets/images/png/Ellipse 52.png",
"title": "Ryan Dorwat",
"mainImg": "assets/images/png/Rectangle 25.png",
"containerTitle": [
'Football',
'Teams player',
'Events',
'Marathon',
'Events'
],
"desciption": "",
"create_at": '1 hour',
"total_comments": 20,
"total_likes": 20,
"total_save": 10,
"community_name": 'text',
},
{
"profileImg": "assets/images/png/Ellipse 52.png",
"title": "Ryan Dorwat",
"mainImg": "assets/images/png/Rectangle 25.png",
"containerTitle": [
'Football',
'Teams player',
'Events',
'Marathon',
'Events'
],
"desciption": "",
"create_at": '1 hour',
"total_comments": 20,
"total_likes": 20,
"total_save": 10,
"community_name": 'text',
},
];
bool _isDataInitialized = false;
bool _isDataInitialized = true;
Future<void> setValues() async {
if (_isDataInitialized) return; // Check if data is already initialized
try {
await _initializeData();
setState(() {
_isDataInitialized = true;
});
} catch (e) {
// Handle any errors that occur during the fetch
print('Error fetching data: $e');
if (_isDataInitialized) {
await _fetchIcons();
_isDataInitialized = false;
}
}
_sortTags(index) {
var tags = popularpostobj!.data[index].attachTags
.where((tag) => tag.manageTag?.name?.isNotEmpty ?? false)
.map((tag) => tag.manageTag!)
.toList();
return tags;
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
@@ -2722,143 +2508,21 @@ class _PopularTabState extends State<PopularTab> {
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());
var tags = popularData.attachTags
.where((tag) =>
tag.manageTag?.name?.isNotEmpty ?? false)
.map((tag) => tag.manageTag!)
.toList();
popularpostobj!.data[index].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"],
tags: tags,
description: popularData.caption ?? 'test',
tags: _sortTags(index),
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(),
mainImagetap: () {
Get.toNamed(RouteName.postdetailsScreen,
arguments: {
"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<String>(
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<String>(
value:
selectedReaction.id.toString(),
icon: Image.network(
selectedReaction.image,
width: 24,
height: 24,
fit: BoxFit.cover,
),
)
: Reaction<String>(
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,
),
commonObj: popularpostobj!.data[index],
forWhichTab: 'popular',
reactions: _reactions,
selectedReactions: _selectedReactions,
),
// 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)
],
);

View File

@@ -149,7 +149,7 @@ class _AllTabsState extends State<AllTabs> {
@override
void initState() {
postId = Get.arguments['postId'];
postId = Get.arguments['postId'].toString();
alltabfuture = LikePostApi().postLike({'manage_posts_xid': postId});
super.initState();
@@ -226,9 +226,10 @@ class _LikeTabsState extends State<LikeTabs> {
@override
void initState() {
postId = Get.arguments['postId'];
postId = Get.arguments['postId'].toString();
liketabfuture = LikePostApi() .postLike({'manage_posts_xid': postId, 'like_icons_xid': 1});
liketabfuture = LikePostApi()
.postLike({'manage_posts_xid': postId, 'like_icons_xid': 1});
super.initState();
}
@@ -303,9 +304,10 @@ class _FavouriteTabsState extends State<FavouriteTabs> {
@override
void initState() {
postId = Get.arguments['postId'];
postId = Get.arguments['postId'].toString();
favouritetabfuture = LikePostApi() .postLike({'manage_posts_xid': postId, 'like_icons_xid': 2});
favouritetabfuture = LikePostApi()
.postLike({'manage_posts_xid': postId, 'like_icons_xid': 2});
super.initState();
}
@@ -380,8 +382,9 @@ class _PartyTabsState extends State<PartyTabs> {
@override
void initState() {
postId = Get.arguments['postId'];
partytabfuture = LikePostApi().postLike({'manage_posts_xid': postId, 'like_icons_xid': 3});
postId = Get.arguments['postId'].toString();
partytabfuture = LikePostApi()
.postLike({'manage_posts_xid': postId, 'like_icons_xid': 3});
super.initState();
}