diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index 8cb1ec7..70bceed 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -541,6 +541,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -800,6 +842,13 @@
+
+
+
+
+
+
+
@@ -1066,6 +1115,12 @@
+
+
+
+
+
+
@@ -1103,6 +1158,7 @@
+
diff --git a/Sources/justMUSIC/lib/screens/detail_post_screen.dart b/Sources/justMUSIC/lib/screens/detail_post_screen.dart
index 373ce89..397983e 100644
--- a/Sources/justMUSIC/lib/screens/detail_post_screen.dart
+++ b/Sources/justMUSIC/lib/screens/detail_post_screen.dart
@@ -49,6 +49,10 @@ class _DetailPostScreenState extends State {
return MyApp.userViewModel.userCurrent.musics_likes.contains(widget.post.music.id);
}
+ bool isLiked() {
+ return widget.post.likes.contains(MyApp.userViewModel.userCurrent.id);
+ }
+
@override
void dispose() {
MyApp.audioPlayer.release();
@@ -294,7 +298,71 @@ class _DetailPostScreenState extends State {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- SvgPicture.asset("assets/images/heart.svg", semanticsLabel: 'Like Logo'),
+ Column(
+ children: [
+ GestureDetector(
+ onTap: () async {
+ var bool = await MyApp.postViewModel
+ .addOrDeleteFavoritePost(widget.post.id);
+ if (!bool) {
+ widget.post.likes.add(MyApp.userViewModel.userCurrent.id);
+ } else {
+ widget.post.likes.remove(MyApp.userViewModel.userCurrent.id);
+ }
+ !bool
+ ? ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(
+ content: Text("Vous avez liké cette capsule",
+ style: TextStyle(fontWeight: FontWeight.bold)),
+ backgroundColor: primaryColor,
+ closeIconColor: Colors.white,
+ ),
+ )
+ : ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(
+ content: SnackBar(
+ content: Text("Vous avez supprimé votre like",
+ style: TextStyle(fontWeight: FontWeight.bold)),
+ backgroundColor: primaryColor,
+ closeIconColor: Colors.white,
+ ),
+ backgroundColor: Colors.red,
+ closeIconColor: Colors.white,
+ ),
+ );
+ setState(() {});
+ },
+ child: SvgPicture.asset(
+ "assets/images/heart.svg",
+ semanticsLabel: 'Like Logo',
+ color: isLiked() ? primaryColor : Colors.white,
+ ),
+ ),
+ Container(
+ padding: EdgeInsets.only(top: 8),
+ height: 30,
+ child: FutureBuilder>(
+ future: MyApp.postViewModel.getLikesByPostId(widget.post.id),
+ builder:
+ (BuildContext context, AsyncSnapshot> snapshot) {
+ if (snapshot.hasData) {
+ return Text(snapshot.data!.length.toString(),
+ style: GoogleFonts.plusJakartaSans(
+ color: Colors.white,
+ fontWeight: FontWeight.w800,
+ ));
+ } else {
+ return Container(
+ child: Center(
+ child: CupertinoActivityIndicator(),
+ ),
+ );
+ }
+ },
+ ),
+ )
+ ],
+ ),
Column(
children: [
GestureDetector(
diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart
index f8a74db..82bd2d0 100644
--- a/Sources/justMUSIC/lib/services/PostService.dart
+++ b/Sources/justMUSIC/lib/services/PostService.dart
@@ -7,8 +7,7 @@ import 'package:firebase_storage/firebase_storage.dart';
import '../main.dart';
class PostService {
- createPost(String? description, String idMusic, File? image,
- Tuple2? location) async {
+ createPost(String? description, String idMusic, File? image, Tuple2? location) async {
var id = MyApp.userViewModel.userCurrent.id;
final post = {
"user_id": id,
@@ -42,14 +41,11 @@ class PostService {
deletePost() {}
- Future>>> getPopularPosts(
- {int limit = 10, int offset = 0}) async {
+ Future>>> getPopularPosts({int limit = 10, int offset = 0}) async {
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
- Timestamp twentyFourHoursAgoTimestamp =
- Timestamp.fromDate(twentyFourHoursAgo);
+ Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
- QuerySnapshot