feed and latest fixed

This commit is contained in:
jayesh
2024-08-02 18:43:12 +05:30
parent 053048de06
commit 1a03b61b6f
6 changed files with 657 additions and 715 deletions

View File

@@ -0,0 +1,36 @@
class ConvertServerDateToUserDate {
convertServerDateToReadableFormate(String? createAtstring) {
if (createAtstring == null || createAtstring.isEmpty) {
createAtstring = DateTime.now().toIso8601String();
}
String? timeAgo;
try {
DateTime postDateTime = DateTime.parse(createAtstring);
DateTime now = DateTime.now();
Duration difference = now.difference(postDateTime);
if (difference.inDays > 365) {
timeAgo = '${(difference.inDays / 365).floor()} years ago';
} else if (difference.inDays > 30) {
timeAgo = '${(difference.inDays / 30).floor()} months ago';
} else if (difference.inDays > 7) {
timeAgo = '${(difference.inDays / 7).floor()} weeks ago';
} else if (difference.inDays > 0) {
timeAgo = '${difference.inDays} days ago';
} else if (difference.inHours > 0) {
timeAgo = '${difference.inHours} hours ago';
} else if (difference.inMinutes > 0) {
timeAgo = '${difference.inMinutes} minutes ago';
} else {
timeAgo = '${difference.inSeconds} seconds ago';
}
print("Time ago: $timeAgo");
return timeAgo;
} catch (e) {
print("Error parsing date: $e");
String timeAgo = 'Unknown';
}
}
}

View File

@@ -92,6 +92,7 @@ class ApiUrls {
static const getblockuser = "${baseUrl}fetch-blocked-profile";
static const postblockuser = "${baseUrl}block-profile";
static const getlatestpost = "${baseUrl}fetch-latest-post";
static const getfeedpost = "${baseUrl}fetch-post";
static const tagcommunityuser = "${baseUrl}fetch-communities-tags-to-pin";
// Individual

View File

@@ -8,7 +8,10 @@ import 'package:regroup/Common/CommonBottomNavigationBar.dart';
import 'package:regroup/Common/CommonGlassmorphism.dart';
import 'package:regroup/Common/CommonTabBar.dart';
import 'package:regroup/Common/CommonWidget.dart';
import 'package:regroup/Common/ConvertServerDateToUserDate.dart';
import 'package:regroup/Common/controller/MainScreen.dart';
import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart';
import 'package:regroup/Main_Screens/Community/ViewModel/FeedPost.dart';
import 'package:regroup/Main_Screens/Community/ViewModel/LatestPost.dart';
// import 'package:regroup/Feed%20Module/sidemenu/sidemenu.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
@@ -23,16 +26,9 @@ class CommunityScreen extends StatefulWidget {
State<CommunityScreen> createState() => _CommunityScreenState();
}
final List<String> titles = [
'Race',
'Swimming',
'Events',
'Swimming',
'Events',
];
class _CommunityScreenState extends State<CommunityScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey1 = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -122,7 +118,7 @@ class _CommunityScreenState extends State<CommunityScreen> {
Expanded(
child: TabBarView(
children: [
feedTabData(),
const FeedTab(),
popularTab(),
const LatestTab(),
],
@@ -168,106 +164,148 @@ class _CommunityScreenState extends State<CommunityScreen> {
}
}
Widget feedTabData() {
List feedTabData = [
{
"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',
},
];
class FeedTab extends StatefulWidget {
const FeedTab({super.key});
return Column(
children: [
sizedBoxHeight(20.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: feedTabData.length,
itemBuilder: (context, index) {
return Column(
children: [
normalcardtile2(
profileImg: feedTabData[index]["profileImg"],
title: feedTabData[index]["title"],
mainImg: feedTabData[index]["mainImg"],
containerTitle: feedTabData[index]["containerTitle"],
description: 'test',
create_at: '1 hour',
total_comments: '20',
total_likes: '20',
total_save: '10',
community_name: 'text',
@override
State<FeedTab> createState() => _FeedTabState();
}
class _FeedTabState extends State<FeedTab> {
late Future feedfuture;
@override
void initState() {
feedfuture = FeedpostApi().getFeedPostApi();
super.initState();
}
List<PinnedPost> combinedList = [];
setValues() {
combinedList.addAll(feedpostobj!.data!.pinnedCommunityPost);
combinedList.addAll(feedpostobj!.data!.pinnedUserPost);
combinedList.addAll(feedpostobj!.data!.pinnedTagsPost);
// for (var i = 0; i < feedpostobj!.data!.pinnedCommunityPost.length; i++) {
// }
// for (var j = 0; j < feedpostobj!.data!.pinnedUserPost.length; j++) {
// }
// for (var k = 0; k < feedpostobj!.data!.pinnedTagsPost.length; k++) {
// }
}
@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,
),
);
}
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),
),
sizedBoxHeight(20.h)
],
);
},
),
),
],
);
),
Column(
children: [
sizedBoxHeight(16.h),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: combinedList.length,
itemBuilder: (context, index) {
var timeAgo = ConvertServerDateToUserDate()
.convertServerDateToReadableFormate(
combinedList[index].createdAt.toString());
if (index == 1) {
return announcecardtile(
profileImg: combinedList[index]
.iamPrincipal!
.profilePhoto ??
'',
title: combinedList[index].iamPrincipal!.fullName ??
'',
mainImg: combinedList[index].image ?? '',
containerTitle:
combinedList[index].tagNames ?? [''],
create_at: timeAgo,
community_name:
combinedList[index].community!.communityName ??
'',
totalcomments:
combinedList[index].totalComment.toString(),
description: combinedList[index].caption ?? '',
totalSave: combinedList[index].totalSave.toString(),
);
} else {
return Column(
children: [
normalcardtile2(
profileImg: combinedList[index]
.iamPrincipal!
.profilePhoto ??
'',
title: combinedList[index]
.iamPrincipal!
.fullName ??
'',
mainImg: combinedList[index].image ?? '',
containerTitle:
combinedList[index].tagNames ?? [],
description: combinedList[index].caption ?? '',
create_at: timeAgo,
total_comments:
combinedList[index].totalComment.toString(),
total_likes:
combinedList[index].likecount.toString(),
total_save:
combinedList[index].totalSave.toString(),
community_name: combinedList[index]
.community!
.communityName
.toString(),
),
sizedBoxHeight(20.h)
],
);
}
},
),
),
],
),
],
);
}
return Container();
},
);
}
}
Widget normalcardtile2({
@@ -442,12 +480,13 @@ Widget normalcardtile2({
height: 360,
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
mainImg,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
mainImg,
),
),
)),
),
),
),
sizedBoxHeight(20.h),
@@ -613,363 +652,20 @@ Widget normalcardtile2({
],
),
),
Column(
children: [
Image.asset(
'assets/images/png/Frame 1000004089.png',
height: 19.h,
width: 19.w,
),
sizedBoxHeight(8.h),
text11w400_FCFCFC('Save')
],
)
],
),
sizedBoxHeight(12.h),
commonDivider(),
sizedBoxHeight(12.h),
]),
),
],
));
}
Widget normalcardtile({
required String profileImg,
required String title,
required String mainImg,
required List<String> containerTitle,
}) {
var 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';
}
}
return commonGlassContainer(
width: double.infinity,
height: 570.h,
border: 0,
borderradius: 1,
customWidget: Column(
children: [
sizedBoxHeight(25.h),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
foregroundImage: AssetImage(profileImg),
radius: 25.r,
),
sizedBoxWidth(12.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16w400_FCFCFC(title),
sizedBoxHeight(5.h),
Row(
children: [
Image.asset(
'assets/images/png/community 1 (traced).png',
height: 14.w,
width: 14.w,
),
sizedBoxWidth(7.w),
text12w400_FCFCFC('Active alliance network'),
sizedBoxWidth(7.w),
Icon(
Icons.circle,
color: const Color(0xFFFCFCFC),
size: 4.sp,
),
sizedBoxWidth(6.w),
text12w400_FCFCFC('1 Hour ago'),
],
)
],
),
const Spacer(),
PopupMenuButton(
surfaceTintColor: const Color(0xFF222935),
constraints: BoxConstraints.tightFor(width: 176.w),
offset: const Offset(0, 50),
color: const Color(0xFF222935),
tooltip: "",
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
onTap: () {},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12.w),
child: Row(
children: [
Text(
'Report Post',
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontWeight: FontWeight.w800,
fontFamily: "Nunito Sans",
),
),
const Spacer(),
Image.asset(
"assets/images/png/Vector (5).png",
height: 15.h,
width: 15.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12.w),
child: Row(
children: [
Text(
'Share post',
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontWeight: FontWeight.w800,
fontFamily: "Nunito Sans",
),
),
const Spacer(),
Image.asset(
"assets/images/png/share.png",
height: 20.h,
width: 20.w,
)
],
),
),
),
const PopupMenuDivider(),
PopupMenuItem(
onTap: () {},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12.w),
child: Row(
children: [
Text(
'Pin',
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontWeight: FontWeight.w800,
fontFamily: "Nunito Sans",
),
),
const Spacer(),
Image.asset(
"assets/images/png/f7_pin-fill (2).png",
height: 25.h,
width: 25.w,
)
],
),
),
),
],
child: Image.asset(
'assets/images/png/Group 1000004071.png',
width: 16.w,
height: 18.h,
),
),
sizedBoxWidth(5.w)
],
),
),
sizedBoxHeight(20.h),
GestureDetector(
onTap: () {
Get.toNamed(RouteName.postdetailsScreen);
},
child: SizedBox(
height: 163.h,
width: double.infinity,
child: Image.asset(
mainImg,
fit: BoxFit.cover,
),
)),
sizedBoxHeight(20.h),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Column(children: [
SizedBox(
height: 30.h,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: containerTitle.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(right: 12.w),
child: GestureDetector(
onTap: () {
Get.toNamed(RouteName.cyclescreen);
},
child: containertile(
text: ("#${containerTitle[index]}"))),
);
},
),
),
sizedBoxHeight(20.h),
text16w400_FCFCFC(
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s . . ."),
Row(children: [
InkWell(
onTap: () {
Get.toNamed(RouteName.reactionview);
},
child: stackReaction(number: '20', containerImages: [
'assets/images/png/f7_hand-thumbsup.png',
'assets/images/png/heart 2.png',
'assets/images/png/party-popper 2.png'
]),
),
const Spacer(),
commonGlassContainer(
border: 0.43,
width: 30.w,
height: 30.h,
opacity1: 0.05,
opacity2: 0.06,
borderradius: 100,
customWidget: Center(
child: Image.asset(
'assets/images/png/Frame 1000004088.png',
height: 13.h,
width: 13.w,
),
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC('20'),
sizedBoxWidth(20.w),
commonGlassContainer(
border: 0.43,
width: 30.w,
height: 30.h,
borderradius: 100,
opacity1: 0.05,
opacity2: 0.06,
customWidget: Center(
child: Image.asset(
'assets/images/png/Vector (1).png',
height: 12.h,
width: 12.w,
),
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC('10'),
]),
sizedBoxHeight(12.h),
commonDivider(),
sizedBoxHeight(12.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(() {
return ReactionButton<String>(
onReactionChanged: (reaction) {
updateImage(reaction?.value ?? 'like');
debugPrint('Selected value: ${reaction?.value}');
},
reactions: <Reaction<String>?>[
Reaction<String>(
value: 'like',
previewIcon: _buildReactionsPreviewIcon(
'assets/images/png/f7_hand-thumbsup.png'),
icon: _buildReactionsIcon(
'assets/images/png/f7_hand-thumbsup.png',
),
),
Reaction<String>(
value: 'heart',
previewIcon: _buildReactionsPreviewIcon(
'assets/images/png/heart 2.png'),
icon: _buildReactionsIcon(
'assets/images/png/heart 2.png'),
),
Reaction<String>(
value: 'party',
previewIcon: _buildReactionsPreviewIcon(
'assets/images/png/party-popper 2.png'),
icon: _buildReactionsIcon(
'assets/images/png/party-popper 2.png'),
),
],
selectedReaction: Reaction<String>(
value: 'like',
icon: _buildReactionsIcon(
'assets/images/png/f7_hand-thumbs.png'),
),
boxColor: Colors.white,
boxElevation: 2,
boxRadius: 30,
itemsSpacing: 8,
itemScale: 0.4,
itemSize: const Size(45, 45),
boxPadding: const EdgeInsets.all(8),
boxAnimationDuration:
const Duration(milliseconds: 200),
itemAnimationDuration:
const Duration(milliseconds: 500),
hoverDuration: const Duration(milliseconds: 700),
// toggle: false,
direction: ReactionsBoxAlignment.rtl,
child: _buildReactionsIcon(mainImage.value),
);
})
],
),
GestureDetector(
onTap: () {
Get.toNamed(RouteName.postdetailsScreen);
},
InkWell(
onTap: () {},
child: Column(
children: [
Image.asset(
'assets/images/png/Frame 1000004088.png',
'assets/images/png/Frame 1000004089.png',
height: 19.h,
width: 19.w,
),
sizedBoxHeight(8.h),
text11w400_FCFCFC('Comment')
text11w400_FCFCFC('Save')
],
),
),
Column(
children: [
Image.asset(
'assets/images/png/Frame 1000004089.png',
height: 19.h,
width: 19.w,
),
sizedBoxHeight(8.h),
text11w400_FCFCFC('Save')
],
)
],
),
sizedBoxHeight(12.h),
@@ -985,6 +681,13 @@ Widget announcecardtile({
required String profileImg,
required String title,
required String mainImg,
required String create_at,
required String community_name,
required String totalcomments,
required String totalSave,
required String description,
// required DateTime create_at,
required List<String> containerTitle,
}) {
var mainImage = 'assets/images/png/uiw_like-o.png'.obs;
@@ -1003,7 +706,7 @@ Widget announcecardtile({
children: [
commonGlassUIBlue(
width: double.infinity,
height: 610.h,
height: 780.h,
borderRadius: BorderRadius.circular(1),
customWidget: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -1020,7 +723,7 @@ Widget announcecardtile({
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
foregroundImage: AssetImage(profileImg),
foregroundImage: NetworkImage(profileImg),
radius: 25.r,
),
sizedBoxWidth(12.w),
@@ -1037,7 +740,7 @@ Widget announcecardtile({
width: 14.w,
),
sizedBoxWidth(7.w),
text12w400_FCFCFC('Active alliance network'),
text12w400_FCFCFC(community_name),
sizedBoxWidth(7.w),
Icon(
Icons.circle,
@@ -1045,7 +748,7 @@ Widget announcecardtile({
size: 4.sp,
),
sizedBoxWidth(6.w),
text12w400_FCFCFC('1 Hour ago'),
text12w400_FCFCFC(create_at),
],
)
],
@@ -1148,17 +851,15 @@ Widget announcecardtile({
),
sizedBoxHeight(20.h),
GestureDetector(
onTap: () {
// Get.toNamed(RouteName.postdetailsScreen);
},
child: SizedBox(
height: 163.h,
width: double.infinity,
child: Image.asset(
mainImg,
fit: BoxFit.cover,
),
)),
onTap: () {
// Get.toNamed(RouteName.postdetailsScreen);
},
child: Container(
height: 390.h,
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage(mainImg))),
),
),
sizedBoxHeight(20.h),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
@@ -1176,15 +877,26 @@ Widget announcecardtile({
onTap: () {
// Get.toNamed(RouteName.cyclescreen);
},
child:
containertile2(text: containerTitle[index])),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
containertile2(text: containerTitle[index]),
],
)),
);
},
),
),
sizedBoxHeight(20.h),
text16w400_FCFCFC(
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s . . ."),
SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16w400_FCFCFC(description),
],
),
),
Row(children: [
InkWell(
onTap: () {
@@ -1214,7 +926,7 @@ Widget announcecardtile({
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC('20'),
text14w400_FCFCFC(totalcomments),
sizedBoxWidth(20.w),
commonContainer(
width: 30.w,
@@ -1233,7 +945,7 @@ Widget announcecardtile({
),
),
sizedBoxWidth(12.w),
text14w400_FCFCFC('10'),
text14w400_FCFCFC(totalSave),
]),
sizedBoxHeight(12.h),
commonDivider(),
@@ -1553,93 +1265,62 @@ class _LatestTabState extends State<LatestTab> {
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: latestpostobj!.data!.length,
itemCount: latestpostobj!.data.length,
itemBuilder: (context, index) {
var timeAgo = ConvertServerDateToUserDate()
.convertServerDateToReadableFormate(latestpostobj!
.data[index].createdAt
.toString());
if (index == 1) {
return announcecardtile(
profileImg: latestpostobj!.data![index]
.iamPrincipal!.profilePhoto ??
'',
title: latestpostobj!.data![index].caption ?? '',
mainImg: 'assets/images/png/Rectangle 46.png',
containerTitle: [
'Race',
'Swimming',
'Events',
'Marathon',
'Events'
]);
profileImg: latestpostobj!
.data[index].iamPrincipal!.profilePhoto ??
'',
title: latestpostobj!
.data[index].iamPrincipal!.fullName ??
'',
mainImg: latestpostobj!.data[index].image ?? '',
containerTitle:
latestpostobj!.data[index].tagNames ?? [''],
create_at: timeAgo,
community_name: latestpostobj!
.data[index].community!.communityName ??
'',
totalcomments: latestpostobj!
.data[index].totalComment
.toString(),
description:
latestpostobj!.data[index].caption ?? '',
totalSave:
latestpostobj!.data[index].totalSave.toString(),
);
} else {
String? createAtstring =
latestpostobj!.data![index].createdAt;
if (createAtstring == null ||
createAtstring.isEmpty) {
createAtstring = DateTime.now().toIso8601String();
}
String? timeAgo;
try {
DateTime postDateTime =
DateTime.parse(createAtstring);
DateTime now = DateTime.now();
Duration difference = now.difference(postDateTime);
if (difference.inDays > 365) {
timeAgo =
'${(difference.inDays / 365).floor()} years ago';
} else if (difference.inDays > 30) {
timeAgo =
'${(difference.inDays / 30).floor()} months ago';
} else if (difference.inDays > 7) {
timeAgo =
'${(difference.inDays / 7).floor()} weeks ago';
} else if (difference.inDays > 0) {
timeAgo = '${difference.inDays} days ago';
} else if (difference.inHours > 0) {
timeAgo = '${difference.inHours} hours ago';
} else if (difference.inMinutes > 0) {
timeAgo = '${difference.inMinutes} minutes ago';
} else {
timeAgo = '${difference.inSeconds} seconds ago';
}
print("Time ago: $timeAgo");
} catch (e) {
print("Error parsing date: $e");
String timeAgo = 'Unknown';
}
return Column(
children: [
normalcardtile2(
profileImg: latestpostobj!.data![index]
profileImg: latestpostobj!.data[index]
.iamPrincipal!.profilePhoto ??
'',
title: latestpostobj!
.data![index].iamPrincipal!.fullName ??
.data[index].iamPrincipal!.fullName ??
'',
mainImg:
latestpostobj!.data![index].image ?? '',
mainImg: latestpostobj!.data[index].image ?? '',
containerTitle:
latestpostobj!.data![index].tagNames ??
[''],
latestpostobj!.data[index].tagNames ?? [''],
description:
latestpostobj!.data![index].caption ?? '',
latestpostobj!.data[index].caption ?? '',
create_at: timeAgo,
total_comments: latestpostobj!
.data![index].totalComment
.toString() ??
'',
.data[index].totalComment
.toString(),
total_likes: latestpostobj!
.data![index].likecount
.toString() ??
'',
total_save: latestpostobj!
.data![index].totalSave
.toString() ??
'',
.data[index].likecount
.toString(),
total_save: latestpostobj!.data[index].totalSave
.toString(),
community_name: latestpostobj!
.data![index].community!.communityName
.toString() ??
'',
.data[index].community!.communityName
.toString(),
),
sizedBoxHeight(20.h)
],

View File

@@ -0,0 +1,197 @@
class FeedPostModel {
FeedPostModel({
required this.status,
required this.statusCode,
required this.message,
required this.data,
});
final String? status;
final int? statusCode;
final String? message;
final Data? data;
factory FeedPostModel.fromJson(Map<String, dynamic> json){
return FeedPostModel(
status: json["status"],
statusCode: json["status_code"],
message: json["message"],
data: json["data"] == null ? null : Data.fromJson(json["data"]),
);
}
}
class Data {
Data({
required this.pinnedCommunityPost,
required this.pinnedUserPost,
required this.pinnedTagsPost,
});
final List<PinnedPost> pinnedCommunityPost;
final List<PinnedPost> pinnedUserPost;
final List<PinnedPost> pinnedTagsPost;
factory Data.fromJson(Map<String, dynamic> json){
return Data(
pinnedCommunityPost: json["pinned_community_post"] == null ? [] : List<PinnedPost>.from(json["pinned_community_post"]!.map((x) => PinnedPost.fromJson(x))),
pinnedUserPost: json["pinned_user_post"] == null ? [] : List<PinnedPost>.from(json["pinned_user_post"]!.map((x) => PinnedPost.fromJson(x))),
pinnedTagsPost: json["pinned_tags_post"] == null ? [] : List<PinnedPost>.from(json["pinned_tags_post"]!.map((x) => PinnedPost.fromJson(x))),
);
}
}
class PinnedPost {
PinnedPost({
required this.id,
required this.likecount,
required this.tagsXid,
required this.isILiked,
required this.totalComment,
required this.totalSave,
required this.iamPrincipalXid,
required this.postIn,
required this.caption,
required this.image,
required this.manageTagsXids,
required this.postAs,
required this.ctaTitle,
required this.ctaLink,
required this.createdAt,
required this.tagNames,
required this.likeIcon,
required this.iamPrincipal,
required this.community,
});
final int? id;
final int? likecount;
final List<int> tagsXid;
final bool? isILiked;
final int? totalComment;
final int? totalSave;
final int? iamPrincipalXid;
final int? postIn;
final String? caption;
final String? image;
final String? manageTagsXids;
final String? postAs;
final String? ctaTitle;
final String? ctaLink;
final DateTime? createdAt;
final List<String> tagNames;
final LikeIcon? likeIcon;
final IamPrincipal? iamPrincipal;
final Community? community;
factory PinnedPost.fromJson(Map<String, dynamic> json){
return PinnedPost(
id: json["id"],
likecount: json["likecount"],
tagsXid: json["tags_xid"] == null ? [] : List<int>.from(json["tags_xid"]!.map((x) => x)),
isILiked: json["is_i_liked"],
totalComment: json["total_comment"],
totalSave: json["total_save"],
iamPrincipalXid: json["iam_principal_xid"],
postIn: json["post_in"],
caption: json["caption"],
image: json["image"],
manageTagsXids: json["manage_tags_xids"],
postAs: json["post_as"],
ctaTitle: json["cta_title"],
ctaLink: json["cta_link"],
createdAt: DateTime.tryParse(json["created_at"] ?? ""),
tagNames: json["tag_names"] == null ? [] : List<String>.from(json["tag_names"]!.map((x) => x)),
likeIcon: json["likeIcon"] == null ? null : LikeIcon.fromJson(json["likeIcon"]),
iamPrincipal: json["iam_principal"] == null ? null : IamPrincipal.fromJson(json["iam_principal"]),
community: json["community"] == null ? null : Community.fromJson(json["community"]),
);
}
}
class Community {
Community({
required this.id,
required this.communityProfilePhoto,
required this.communityName,
});
final int? id;
final String? communityProfilePhoto;
final String? communityName;
factory Community.fromJson(Map<String, dynamic> json){
return Community(
id: json["id"],
communityProfilePhoto: json["community_profile_photo"],
communityName: json["community_name"],
);
}
}
class IamPrincipal {
IamPrincipal({
required this.id,
required this.principalTypeXid,
required this.userName,
required this.fullName,
required this.profilePhoto,
});
final int? id;
final int? principalTypeXid;
final String? userName;
final String? fullName;
final String? profilePhoto;
factory IamPrincipal.fromJson(Map<String, dynamic> json){
return IamPrincipal(
id: json["id"],
principalTypeXid: json["principal_type_xid"],
userName: json["user_name"],
fullName: json["full_name"],
profilePhoto: json["profile_photo"],
);
}
}
class LikeIcon {
LikeIcon({
required this.likeIconsXid,
required this.likeIcon,
});
final int? likeIconsXid;
final LikeIconClass? likeIcon;
factory LikeIcon.fromJson(Map<String, dynamic> json){
return LikeIcon(
likeIconsXid: json["like_icons_xid"],
likeIcon: json["like_icon"] == null ? null : LikeIconClass.fromJson(json["like_icon"]),
);
}
}
class LikeIconClass {
LikeIconClass({
required this.id,
required this.image,
});
final int? id;
final String? image;
factory LikeIconClass.fromJson(Map<String, dynamic> json){
return LikeIconClass(
id: json["id"],
image: json["image"],
);
}
}

View File

@@ -1,183 +1,176 @@
class LatestpostModel {
String? status;
int? statusCode;
String? message;
List<Data>? data;
LatestpostModel({
required this.status,
required this.statusCode,
required this.message,
required this.data,
});
LatestpostModel({this.status, this.statusCode, this.message, this.data});
final String? status;
final int? statusCode;
final String? message;
final List<Datum> data;
LatestpostModel.fromJson(Map<String, dynamic> json) {
status = json['status'];
statusCode = json['status_code'];
message = json['message'];
if (json['data'] != null) {
data = <Data>[];
json['data'].forEach((v) {
data!.add(Data.fromJson(v));
});
factory LatestpostModel.fromJson(Map<String, dynamic> json){
return LatestpostModel(
status: json["status"],
statusCode: json["status_code"],
message: json["message"],
data: json["data"] == null ? [] : List<Datum>.from(json["data"]!.map((x) => Datum.fromJson(x))),
);
}
}
Map<String, dynamic> toJson() {
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();
}
return data;
}
}
class Data {
int? id;
int? likecount;
List<int>? tagsXid;
bool? isILiked;
int? totalComment;
int? totalSave;
int? iamPrincipalXid;
int? postIn;
String? caption;
String? image;
String? manageTagsXids;
String? postAs;
String? ctaTitle;
String? ctaLink;
String? createdAt;
List<String>? tagNames;
String? likeIcon;
IamPrincipal? iamPrincipal;
Community? community;
class Datum {
Datum({
required this.id,
required this.likecount,
required this.tagsXid,
required this.isILiked,
required this.totalComment,
required this.totalSave,
required this.iamPrincipalXid,
required this.postIn,
required this.caption,
required this.image,
required this.manageTagsXids,
required this.postAs,
required this.ctaTitle,
required this.ctaLink,
required this.createdAt,
required this.tagNames,
required this.likeIcon,
required this.iamPrincipal,
required this.community,
});
Data(
{this.id,
this.likecount,
this.tagsXid,
this.isILiked,
this.totalComment,
this.totalSave,
this.iamPrincipalXid,
this.postIn,
this.caption,
this.image,
this.manageTagsXids,
this.postAs,
this.ctaTitle,
this.ctaLink,
this.createdAt,
this.tagNames,
this.likeIcon,
this.iamPrincipal,
this.community});
final int? id;
final int? likecount;
final List<int> tagsXid;
final bool? isILiked;
final int? totalComment;
final int? totalSave;
final int? iamPrincipalXid;
final int? postIn;
final String? caption;
final String? image;
final String? manageTagsXids;
final String? postAs;
final String? ctaTitle;
final String? ctaLink;
final DateTime? createdAt;
final List<String> tagNames;
final LikeIcon? likeIcon;
final IamPrincipal? iamPrincipal;
final Community? community;
Data.fromJson(Map<String, dynamic> json) {
id = json['id'];
likecount = json['likecount'];
tagsXid = json['tags_xid'].cast<int>();
isILiked = json['is_i_liked'];
totalComment = json['total_comment'];
totalSave = json['total_save'];
iamPrincipalXid = json['iam_principal_xid'];
postIn = json['post_in'];
caption = json['caption'];
image = json['image'];
manageTagsXids = json['manage_tags_xids'];
postAs = json['post_as'];
ctaTitle = json['cta_title'];
ctaLink = json['cta_link'];
createdAt = json['created_at'];
tagNames = json['tag_names'].cast<String>();
likeIcon = json['likeIcon'];
iamPrincipal = json['iam_principal'] != null
? IamPrincipal.fromJson(json['iam_principal'])
: null;
community = json['community'] != null
? Community.fromJson(json['community'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['likecount'] = likecount;
data['tags_xid'] = tagsXid;
data['is_i_liked'] = isILiked;
data['total_comment'] = totalComment;
data['total_save'] = totalSave;
data['iam_principal_xid'] = iamPrincipalXid;
data['post_in'] = postIn;
data['caption'] = caption;
data['image'] = image;
data['manage_tags_xids'] = manageTagsXids;
data['post_as'] = postAs;
data['cta_title'] = ctaTitle;
data['cta_link'] = ctaLink;
data['created_at'] = createdAt;
data['tag_names'] = tagNames;
data['likeIcon'] = likeIcon;
if (iamPrincipal != null) {
data['iam_principal'] = iamPrincipal!.toJson();
factory Datum.fromJson(Map<String, dynamic> json){
return Datum(
id: json["id"],
likecount: json["likecount"],
tagsXid: json["tags_xid"] == null ? [] : List<int>.from(json["tags_xid"]!.map((x) => x)),
isILiked: json["is_i_liked"],
totalComment: json["total_comment"],
totalSave: json["total_save"],
iamPrincipalXid: json["iam_principal_xid"],
postIn: json["post_in"],
caption: json["caption"],
image: json["image"],
manageTagsXids: json["manage_tags_xids"],
postAs: json["post_as"],
ctaTitle: json["cta_title"],
ctaLink: json["cta_link"],
createdAt: DateTime.tryParse(json["created_at"] ?? ""),
tagNames: json["tag_names"] == null ? [] : List<String>.from(json["tag_names"]!.map((x) => x)),
likeIcon: json["likeIcon"] == null ? null : LikeIcon.fromJson(json["likeIcon"]),
iamPrincipal: json["iam_principal"] == null ? null : IamPrincipal.fromJson(json["iam_principal"]),
community: json["community"] == null ? null : Community.fromJson(json["community"]),
);
}
if (community != null) {
data['community'] = community!.toJson();
}
return data;
}
}
class IamPrincipal {
int? id;
int? principalTypeXid;
String? userName;
String? fullName;
String? profilePhoto;
IamPrincipal(
{this.id,
this.principalTypeXid,
this.userName,
this.fullName,
this.profilePhoto});
IamPrincipal.fromJson(Map<String, dynamic> json) {
id = json['id'];
principalTypeXid = json['principal_type_xid'];
userName = json['user_name'];
fullName = json['full_name'];
profilePhoto = json['profile_photo'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['principal_type_xid'] = principalTypeXid;
data['user_name'] = userName;
data['full_name'] = fullName;
data['profile_photo'] = profilePhoto;
return data;
}
}
class Community {
int? id;
String? communityProfilePhoto;
String? communityName;
Community({
required this.id,
required this.communityProfilePhoto,
required this.communityName,
});
Community({this.id, this.communityProfilePhoto, this.communityName});
final int? id;
final String? communityProfilePhoto;
final String? communityName;
Community.fromJson(Map<String, dynamic> json) {
id = json['id'];
communityProfilePhoto = json['community_profile_photo'];
communityName = json['community_name'];
}
factory Community.fromJson(Map<String, dynamic> json){
return Community(
id: json["id"],
communityProfilePhoto: json["community_profile_photo"],
communityName: json["community_name"],
);
}
}
class IamPrincipal {
IamPrincipal({
required this.id,
required this.principalTypeXid,
required this.userName,
required this.fullName,
required this.profilePhoto,
});
final int? id;
final int? principalTypeXid;
final String? userName;
final dynamic fullName;
final String? profilePhoto;
factory IamPrincipal.fromJson(Map<String, dynamic> json){
return IamPrincipal(
id: json["id"],
principalTypeXid: json["principal_type_xid"],
userName: json["user_name"],
fullName: json["full_name"],
profilePhoto: json["profile_photo"],
);
}
}
class LikeIcon {
LikeIcon({
required this.likeIconsXid,
required this.likeIcon,
});
final int? likeIconsXid;
final LikeIconClass? likeIcon;
factory LikeIcon.fromJson(Map<String, dynamic> json){
return LikeIcon(
likeIconsXid: json["like_icons_xid"],
likeIcon: json["like_icon"] == null ? null : LikeIconClass.fromJson(json["like_icon"]),
);
}
}
class LikeIconClass {
LikeIconClass({
required this.id,
required this.image,
});
final int? id;
final String? image;
factory LikeIconClass.fromJson(Map<String, dynamic> json){
return LikeIconClass(
id: json["id"],
image: json["image"],
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['community_profile_photo'] = communityProfilePhoto;
data['community_name'] = communityName;
return data;
}
}

View File

@@ -0,0 +1,34 @@
// ignore_for_file: file_names
import 'package:regroup/Common/api_urls.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Common/controller/data/network/network_api.dart';
import 'package:regroup/Main_Screens/Community/Model/FeedPostModel.dart';
FeedPostModel? feedpostobj;
class FeedpostApi {
FeedpostApi();
Future<ResponseData<dynamic>> getFeedPostApi() async {
final response = await NetworkApiServices().getApi(ApiUrls.getfeedpost);
if (response.status == ResponseStatus.SUCCESS) {
// dynamic responseData = response.data;
if (response.data["status"] == "success") {
feedpostobj = FeedPostModel.fromJson(response.data);
}
// if (responseData is Map<String, dynamic>) {
// feedpostobj = FeedPostModel.fromJson(responseData);
// }
return ResponseData<dynamic>(
response.data['message'], ResponseStatus.SUCCESS,
data: response.data);
} else {
return ResponseData<dynamic>(
response.data['message'], ResponseStatus.FAILED);
}
}
}