Merge branch 'LIKES_POST_LDE-EKA' into SAVE_SONG_LDE

# Conflicts:
#	.idea/libraries/Dart_Packages.xml
#	Sources/justMUSIC/lib/screens/detail_post_screen.dart
FIX_LIKES_LDE
Lucas Delanier 2 years ago
commit 83f87e4ed3

@ -114,6 +114,27 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="cached_network_image">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib" />
</list>
</value>
</entry>
<entry key="cached_network_image_platform_interface">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image_platform_interface-2.0.0/lib" />
</list>
</value>
</entry>
<entry key="cached_network_image_web">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image_web-1.0.2/lib" />
</list>
</value>
</entry>
<entry key="characters"> <entry key="characters">
<value> <value>
<list> <list>
@ -352,6 +373,20 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="flutter_blurhash">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_blurhash-0.7.0/lib" />
</list>
</value>
</entry>
<entry key="flutter_cache_manager">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_cache_manager-3.3.1/lib" />
</list>
</value>
</entry>
<entry key="flutter_countdown_timer"> <entry key="flutter_countdown_timer">
<value> <value>
<list> <list>
@ -506,6 +541,48 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="google_identity_services_web">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_identity_services_web-0.2.1/lib" />
</list>
</value>
</entry>
<entry key="google_sign_in">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in-6.1.4/lib" />
</list>
</value>
</entry>
<entry key="google_sign_in_android">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_android-6.1.18/lib" />
</list>
</value>
</entry>
<entry key="google_sign_in_ios">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_ios-5.6.2/lib" />
</list>
</value>
</entry>
<entry key="google_sign_in_platform_interface">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_platform_interface-2.4.1/lib" />
</list>
</value>
</entry>
<entry key="google_sign_in_web">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_web-0.12.0+2/lib" />
</list>
</value>
</entry>
<entry key="gradiantbutton"> <entry key="gradiantbutton">
<value> <value>
<list> <list>
@ -667,6 +744,13 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="octo_image">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/octo_image-1.0.2/lib" />
</list>
</value>
</entry>
<entry key="path"> <entry key="path">
<value> <value>
<list> <list>
@ -758,6 +842,20 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="quiver">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/quiver-3.2.1/lib" />
</list>
</value>
</entry>
<entry key="rxdart">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/rxdart-0.27.7/lib" />
</list>
</value>
</entry>
<entry key="sky_engine"> <entry key="sky_engine">
<value> <value>
<list> <list>
@ -786,6 +884,20 @@
</list> </list>
</value> </value>
</entry> </entry>
<entry key="sqflite">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/sqflite-2.3.0/lib" />
</list>
</value>
</entry>
<entry key="sqflite_common">
<value>
<list>
<option value="$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/sqflite_common-2.5.0/lib" />
</list>
</value>
</entry>
<entry key="stack_trace"> <entry key="stack_trace">
<value> <value>
<list> <list>
@ -945,6 +1057,9 @@
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/audioplayers_windows-2.0.2/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/audioplayers_windows-2.0.2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/auto_size_text-3.0.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/auto_size_text-3.0.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/boolean_selector-2.1.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/boolean_selector-2.1.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image_platform_interface-2.0.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image_web-1.0.2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/characters-1.3.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/characters-1.3.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/circular_reveal_animation-2.0.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/circular_reveal_animation-2.0.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/clock-1.1.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/clock-1.1.1/lib" />
@ -978,6 +1093,8 @@
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_storage_platform_interface-4.4.4/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_storage_platform_interface-4.4.4/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_storage_web-3.6.5/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_storage_web-3.6.5/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_animated_play_button-0.3.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_animated_play_button-0.3.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_blurhash-0.7.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_cache_manager-3.3.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_countdown_timer-4.1.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_countdown_timer-4.1.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_keyboard_visibility-5.4.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_keyboard_visibility-5.4.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_keyboard_visibility_linux-1.0.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_keyboard_visibility_linux-1.0.0/lib" />
@ -998,6 +1115,12 @@
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/geolocator_web-2.1.6/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/geolocator_web-2.1.6/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/geolocator_windows-0.1.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/geolocator_windows-0.1.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_fonts-4.0.4/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_fonts-4.0.4/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_identity_services_web-0.2.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in-6.1.4/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_android-6.1.18/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_ios-5.6.2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_platform_interface-2.4.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/google_sign_in_web-0.12.0+2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/gradiantbutton-0.0.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/gradiantbutton-0.0.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/gradient_borders-1.0.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/gradient_borders-1.0.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib" />
@ -1021,6 +1144,7 @@
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/meta-1.9.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/meta-1.9.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/mime-1.0.4/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/mime-1.0.4/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/octo_image-1.0.2/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path-1.8.3/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path-1.8.3/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path_parsing-1.0.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path_parsing-1.0.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path_provider-2.0.15/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/path_provider-2.0.15/lib" />
@ -1034,9 +1158,13 @@
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/platform-3.1.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/platform-3.1.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/plugin_platform_interface-2.1.5/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/plugin_platform_interface-2.1.5/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/pointycastle-3.7.3/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/pointycastle-3.7.3/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/quiver-3.2.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/rxdart-0.27.7/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/smooth_corner-1.1.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/smooth_corner-1.1.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/smooth_list_view-1.0.4/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/smooth_list_view-1.0.4/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/source_span-1.9.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/source_span-1.9.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/sqflite-2.3.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/sqflite_common-2.5.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/stack_trace-1.11.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/stack_trace-1.11.0/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/stream_channel-2.1.1/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/stream_channel-2.1.1/lib" />
<root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/string_scanner-1.2.0/lib" /> <root url="file://$USER_HOME$/AppData/Local/Pub/Cache/hosted/pub.dev/string_scanner-1.2.0/lib" />

@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:pinch_zoom/pinch_zoom.dart';
import 'package:text_scroll/text_scroll.dart'; import 'package:text_scroll/text_scroll.dart';
import 'package:zoom_tap_animation/zoom_tap_animation.dart'; import 'package:zoom_tap_animation/zoom_tap_animation.dart';
import '../components/button_play_component.dart'; import '../components/button_play_component.dart';
@ -44,6 +45,14 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
}); });
} }
bool isSaved() {
return MyApp.userViewModel.userCurrent.musics_likes.contains(widget.post.music.id);
}
bool isLiked() {
return widget.post.likes.contains(MyApp.userViewModel.userCurrent.id);
}
@override @override
void dispose() { void dispose() {
MyApp.audioPlayer.release(); MyApp.audioPlayer.release();
@ -89,26 +98,35 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
child: Container( child: Container(
height: 400, height: 400,
width: double.infinity, width: double.infinity,
child: PinchZoom(
resetDuration: const Duration(milliseconds: 400),
maxScale: 2.5,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
fit: BoxFit.cover,
image: choice ? widget.post.selfie! : widget.post.music.cover!,
fadeInDuration: const Duration(milliseconds: 100),
placeholder: "assets/images/loadingPlaceholder.gif", placeholder: "assets/images/loadingPlaceholder.gif",
), image: choice ? widget.post.selfie! : widget.post.music.cover!,
width: double.infinity,
fit: BoxFit.cover,
)),
), ),
), ),
Column( Column(
children: [ children: [
Container( IgnorePointer(
child: Container(
height: 200, height: 200,
margin: EdgeInsets.only(top: 230), margin: EdgeInsets.only(top: 230),
width: double.infinity, width: double.infinity,
decoration: const BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topCenter, begin: Alignment.topCenter,
end: Alignment.bottomCenter, end: Alignment.bottomCenter,
colors: [Colors.transparent, bgModal], colors: [
stops: [0, 0.8], Colors.transparent,
bgModal.withOpacity(0.5),
bgModal.withOpacity(0.75),
bgModal
],
stops: [0, 0.2, 0.4, 0.8],
), ),
), ),
child: Padding( child: Padding(
@ -240,6 +258,7 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
), ),
), ),
), ),
),
widget.post.description != null widget.post.description != null
? Align( ? Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
@ -274,11 +293,78 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
child: Column( child: Column(
children: [ children: [
Padding( Padding(
padding: EdgeInsets.symmetric(vertical: 20), padding: EdgeInsets.only(top: 30, bottom: 20),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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<List<String>>(
future: MyApp.postViewModel.getLikesByPostId(widget.post.id),
builder:
(BuildContext context, AsyncSnapshot<List<String>> 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: [ children: [
SvgPicture.asset("assets/images/heart.svg", semanticsLabel: 'Like Logo'),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
myFocusNode.requestFocus(); myFocusNode.requestFocus();
@ -286,44 +372,103 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
child: SvgPicture.asset("assets/images/chat.svg", child: SvgPicture.asset("assets/images/chat.svg",
semanticsLabel: 'Chat Logo'), semanticsLabel: 'Chat Logo'),
), ),
SvgPicture.asset("assets/images/add.svg", Container(
semanticsLabel: 'Add playlist Logo'), padding: EdgeInsets.only(top: 8),
SvgPicture.asset("assets/images/save.svg", semanticsLabel: 'Save Logo'), height: 30,
SvgPicture.asset("assets/images/report.svg", semanticsLabel: 'Report Logo'), child: FutureBuilder<List<Comment>>(
],
),
),
FutureBuilder<List<Comment>>(
future: MyApp.commentViewModel.getCommentsByPostId(widget.post.id), future: MyApp.commentViewModel.getCommentsByPostId(widget.post.id),
builder: (BuildContext context, AsyncSnapshot<List<Comment>> snapshot) { builder:
(BuildContext context, AsyncSnapshot<List<Comment>> snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
return Column( return Text(snapshot.data!.length.toString(),
children: [
snapshot.data!.length > 0
? Padding(
padding: const EdgeInsets.all(15.0),
child: RichText(
text: TextSpan(
text: snapshot.data!.length.toString(),
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w800, fontWeight: FontWeight.w800,
));
} else {
return Container(
child: Center(
child: CupertinoActivityIndicator(),
), ),
children: [ );
}
},
),
)
],
),
SvgPicture.asset("assets/images/add.svg",
semanticsLabel: 'Add playlist Logo'),
GestureDetector(
onTap: () async {
var bool = await MyApp.musicViewModel
.addOrDeleteFavoriteMusic(widget.post.music.id);
!bool
? ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: RichText(
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15,
),
children: <TextSpan>[
TextSpan( TextSpan(
text: snapshot.data!.length > 1 text: "${widget.post.music.title}",
? " commentaires" style: TextStyle(fontWeight: FontWeight.bold)),
: " commentaire", TextSpan(text: " ajouté à votre collection"),
],
),
),
backgroundColor: primaryColor,
closeIconColor: Colors.white,
),
)
: ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: RichText(
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontSize: 15,
),
children: <TextSpan>[
TextSpan(
text: "${widget.post.music.title}",
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: " retiré de votre collection"),
],
), ),
), ),
backgroundColor: Colors.red,
closeIconColor: Colors.white,
),
);
setState(() {});
},
child: SvgPicture.asset(
"assets/images/save.svg",
semanticsLabel: 'Save Logo',
color: isSaved() ? primaryColor : Colors.white,
)),
SvgPicture.asset("assets/images/report.svg", semanticsLabel: 'Report Logo'),
], ],
), ),
), ),
) FutureBuilder<List<Comment>>(
: Container(), future: MyApp.commentViewModel.getCommentsByPostId(widget.post.id),
builder: (BuildContext context, AsyncSnapshot<List<Comment>> snapshot) {
if (snapshot.hasData) {
return Column(
children: [
snapshot.data!.length > 0 snapshot.data!.length > 0
? Padding( ? Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20), padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),

@ -7,8 +7,7 @@ import 'package:firebase_storage/firebase_storage.dart';
import '../main.dart'; import '../main.dart';
class PostService { class PostService {
createPost(String? description, String idMusic, File? image, createPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async {
Tuple2<String, String>? location) async {
var id = MyApp.userViewModel.userCurrent.id; var id = MyApp.userViewModel.userCurrent.id;
final post = <String, dynamic>{ final post = <String, dynamic>{
"user_id": id, "user_id": id,
@ -42,14 +41,11 @@ class PostService {
deletePost() {} deletePost() {}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts( Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
{int limit = 10, int offset = 0}) async {
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24)); DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
Timestamp twentyFourHoursAgoTimestamp = Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
Timestamp.fromDate(twentyFourHoursAgo);
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore.instance
.instance
.collection("posts") .collection("posts")
.where("date", isGreaterThan: twentyFourHoursAgoTimestamp) .where("date", isGreaterThan: twentyFourHoursAgoTimestamp)
.limit(limit) .limit(limit)
@ -67,8 +63,7 @@ class PostService {
return Timestamp.fromDate(twentyFourHoursAgo); return Timestamp.fromDate(twentyFourHoursAgo);
} }
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends( Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends({int limit = 10, int offset = 0}) async {
{int limit = 10, int offset = 0}) async {
var timestamp = _getTwentyFourHoursAgoTimestamp(); var timestamp = _getTwentyFourHoursAgoTimestamp();
var response = await FirebaseFirestore.instance var response = await FirebaseFirestore.instance
.collection("posts") .collection("posts")
@ -84,17 +79,12 @@ class PostService {
Future<bool> getAvailable(String idUser) async { Future<bool> getAvailable(String idUser) async {
DateTime today = DateTime.now(); DateTime today = DateTime.now();
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response =
.instance await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
.collection("posts")
.where("user_id", isEqualTo: idUser)
.get();
bool isTodayAvailable = response.docs.any((doc) { bool isTodayAvailable = response.docs.any((doc) {
DateTime date = doc["date"].toDate(); // Assuming the field name is "date" DateTime date = doc["date"].toDate(); // Assuming the field name is "date"
return date.day == today.day && return date.day == today.day && date.month == today.month && date.year == today.year;
date.month == today.month &&
date.year == today.year;
}); });
return !isTodayAvailable; return !isTodayAvailable;
@ -105,15 +95,11 @@ class PostService {
DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 6)); DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 6));
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response =
.instance await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: id).get();
.collection("posts")
.where("user_id", isEqualTo: id)
.get();
List<Map<String, dynamic>?> postList = response.docs List<Map<String, dynamic>?> postList =
.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data()) response.docs.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data()).toList();
.toList();
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
DateTime date = sevenDaysAgo.add(Duration(days: i)); DateTime date = sevenDaysAgo.add(Duration(days: i));
@ -128,4 +114,32 @@ class PostService {
return recapList; return recapList;
} }
Future<List<String>> getLikesByPostId(String id) async {
var response = await FirebaseFirestore.instance.collection("posts").doc(id).get();
if (response.exists) {
var musicFavorite = response.get("likes");
return List.from(musicFavorite);
} else {
return [];
}
}
Future<bool> addOrDeleteFavoritePost(String id) async {
final idUser = MyApp.userViewModel.userCurrent.id;
var postRef = await FirebaseFirestore.instance.collection("posts").doc(id);
var response = await postRef.get();
List<String> likes = List.from(response.get("likes"));
if (!likes.contains(idUser)) {
likes.add(idUser);
await postRef.update({"likes": likes});
return false;
} else {
likes.remove(idUser);
await postRef.update({"likes": likes});
return true;
}
}
} }

@ -22,8 +22,7 @@ class PostViewModel {
List<Post> get bestPosts => _bestPosts; List<Post> get bestPosts => _bestPosts;
// Methods // Methods
addPost(String? description, String idMusic, File? image, addPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async {
Tuple2<String, String>? location) async {
await _postService.createPost(description, idMusic, image, location); await _postService.createPost(description, idMusic, image, location);
} }
@ -91,8 +90,25 @@ class PostViewModel {
Future<bool> getAvailable() async { Future<bool> getAvailable() async {
try { try {
return await _postService return await _postService.getAvailable(MyApp.userViewModel.userCurrent.id);
.getAvailable(MyApp.userViewModel.userCurrent.id); } catch (e) {
print(e);
rethrow;
}
}
Future<List<String>> getLikesByPostId(String id) async {
try {
return await _postService.getLikesByPostId(id);
} catch (e) {
print(e);
rethrow;
}
}
Future<bool> addOrDeleteFavoritePost(String id) async {
try {
return await _postService.addOrDeleteFavoritePost(id);
} catch (e) { } catch (e) {
print(e); print(e);
rethrow; rethrow;

Loading…
Cancel
Save