diff --git a/Sources/justMUSIC/assets/images/empty_bg.png b/Sources/justMUSIC/assets/images/empty_bg.png new file mode 100644 index 0000000..96db989 Binary files /dev/null and b/Sources/justMUSIC/assets/images/empty_bg.png differ diff --git a/Sources/justMUSIC/lib/components/post_component.dart b/Sources/justMUSIC/lib/components/post_component.dart index 8b2c594..d6c5bd4 100644 --- a/Sources/justMUSIC/lib/components/post_component.dart +++ b/Sources/justMUSIC/lib/components/post_component.dart @@ -1,3 +1,5 @@ +import 'dart:js_interop'; + import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -336,16 +338,18 @@ class _PostComponentState extends State with TickerProviderStateM fit: BoxFit.fitHeight, width: double.infinity, ), - Padding( - padding: EdgeInsets.all(15), - child: AutoSizeText( - '“${widget.post.description}”', - style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w400, fontSize: 15.sp), - maxFontSize: 20, - maxLines: 1, - ), - ), + widget.post.description.isNull + ? Container() + : Padding( + padding: EdgeInsets.all(15), + child: AutoSizeText( + '“${widget.post.description}”', + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w400, fontSize: 15.sp), + maxFontSize: 20, + maxLines: 1, + ), + ), widget.post.selfie != null ? Positioned( top: 0, diff --git a/Sources/justMUSIC/lib/screens/feed_screen.dart b/Sources/justMUSIC/lib/screens/feed_screen.dart index 5b0e2de..880cfe9 100644 --- a/Sources/justMUSIC/lib/screens/feed_screen.dart +++ b/Sources/justMUSIC/lib/screens/feed_screen.dart @@ -214,58 +214,104 @@ class _FeedScreenState extends State with SingleTickerProviderStateM @override Widget build(BuildContext context) { return Scaffold( - resizeToAvoidBottomInset: true, - backgroundColor: bgColor, - extendBodyBehindAppBar: true, - body: Container( - width: double.infinity, - child: Stack( - fit: StackFit.expand, - children: [ - Align( - child: CircularRevealAnimation( - animation: animation, - centerOffset: Offset(30.w, -100), - child: Container( - constraints: BoxConstraints(maxWidth: 600), - padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0), - child: ListView.builder( - physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), - clipBehavior: Clip.none, - shrinkWrap: true, - itemCount: displayFeed.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: const EdgeInsets.only(bottom: 40), - child: PostComponent(callback: openDetailPost, post: displayFeed[index], index: index), - ); - }, - )), - ), - ), - Align( - alignment: Alignment.topCenter, - child: IgnorePointer( - child: Container( - height: 240.h, - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topRight, - stops: [0.3, 1], - colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), + resizeToAvoidBottomInset: true, + backgroundColor: bgColor, + extendBodyBehindAppBar: true, + body: displayFeed.isEmpty + ? Container( + width: double.infinity, + child: Stack( + fit: StackFit.expand, + children: [ + Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/images/empty_bg.png"), fit: BoxFit.cover, opacity: 0.3), + ), + child: Padding( + padding: EdgeInsets.only(top: 140.h, left: defaultPadding), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text("Suis tes amis pour voir leurs capsules", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontSize: 23, fontWeight: FontWeight.w800)) + ], + ), + ), + ), + Align( + alignment: Alignment.topCenter, + child: IgnorePointer( + child: Container( + height: 240.h, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topRight, + stops: [0.3, 1], + colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), + ), + ), + ), + Align( + alignment: Alignment.topCenter, + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 800), + child: TopNavBarComponent(callback: changeFeed), + ), + ), + ], ), - ), - ), - Align( - alignment: Alignment.topCenter, - child: ConstrainedBox( - constraints: BoxConstraints(maxWidth: 800), - child: TopNavBarComponent(callback: changeFeed), - ), - ), - ], - ), - ), - ); + ) + : Container( + width: double.infinity, + child: Stack( + fit: StackFit.expand, + children: [ + Align( + child: CircularRevealAnimation( + animation: animation, + centerOffset: Offset(30.w, -100), + child: Container( + constraints: BoxConstraints(maxWidth: 600), + padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0), + child: ListView.builder( + physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), + clipBehavior: Clip.none, + shrinkWrap: true, + itemCount: displayFeed.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.only(bottom: 40), + child: + PostComponent(callback: openDetailPost, post: displayFeed[index], index: index), + ); + }, + )), + ), + ), + Align( + alignment: Alignment.topCenter, + child: IgnorePointer( + child: Container( + height: 240.h, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topRight, + stops: [0.3, 1], + colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), + ), + ), + ), + Align( + alignment: Alignment.topCenter, + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 800), + child: TopNavBarComponent(callback: changeFeed), + ), + ), + ], + ), + )); } } diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart index 55921f5..205c8fa 100644 --- a/Sources/justMUSIC/lib/services/PostService.dart +++ b/Sources/justMUSIC/lib/services/PostService.dart @@ -8,8 +8,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, @@ -29,6 +28,7 @@ class PostService { if (userSnapshot.exists) { int currentNbCapsules = userSnapshot.data()?['nbCapsules'] ?? 0; transaction.update(userRef, {'nbCapsules': currentNbCapsules + 1}); + MyApp.userViewModel.userCurrent.capsules++; } }); @@ -44,13 +44,9 @@ class PostService { getPostsById(String id) {} - Future>>> getPopularPosts( - {int limit = 10, int offset = 0}) async { - QuerySnapshot> response = await FirebaseFirestore.instance - .collection("posts") - .limit(limit) - .orderBy("likes").get(); + Future>>> getPopularPosts({int limit = 10, int offset = 0}) async { + QuerySnapshot> response = + await FirebaseFirestore.instance.collection("posts").limit(limit).orderBy("likes").get(); return response.docs; - } }