change for heart and and count interested people

This commit is contained in:
2025-08-20 23:22:25 +02:00
parent bd5bfa94ca
commit 4a936cc267
4 changed files with 22 additions and 11 deletions

View File

@@ -469,7 +469,7 @@ class _MyHomePageState extends State<ListItemMenu> {
}
}
Future<bool> toggleInterested(String eventId) async {
Future<Map<String, dynamic>> toggleInterested(String eventId) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
final url = Uri.parse("${globals.api}/events/${eventId}/interest");
@@ -488,9 +488,9 @@ class _MyHomePageState extends State<ListItemMenu> {
}
var event = json.decode(response.body);
return event["interested"];
return event;
}
return false;
return {"interested": false, "interested_count": 0};
}
Future<void> fetchPostsByLocation() async {
@@ -895,15 +895,21 @@ class _MyHomePageState extends State<ListItemMenu> {
'en_US';
final dateLongue =
DateFormat('EEEE d MMMM y', locale).format(startDate);
final countInterestedString =
AppLocalizations.of(context)?.count_interested ??
"Interested people number";
final countInterested =
"${countInterestedString} : ${post.interestedCount}";
return ListTile(
title: Text('${post.name!}'),
subtitle: Text('${post.place!}\n${dateLongue}'),
subtitle: Text('${post.place!}\n${dateLongue}\n${countInterested}'),
trailing: IconButton(
onPressed: () async {
try {
final result = await toggleInterested(post.id!);
setState(() {
post.interested = result;
post.interested = result["interested"];
post.interestedCount = result["interested_count"];
});
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
@@ -915,9 +921,11 @@ class _MyHomePageState extends State<ListItemMenu> {
}
},
icon: Icon(
post.interested ?? false ? Icons.star : Icons.star_border,
post.interested ?? false
? Icons.favorite
: Icons.favorite_border,
color:
post.interested ?? false ? Colors.blue : Colors.grey)),
post.interested ?? false ? Colors.red : Colors.grey)),
onTap: () {
Navigator.push(
context,