From 0115e2d29f50a586bb77d488f1320d75295632ef Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Tue, 1 Aug 2023 00:23:26 +0200 Subject: [PATCH] beautifull app when empty friend list and fix empty description --- .idea/libraries/Dart_Packages.xml | 43 +++------------- .../lib/components/post_component.dart | 5 +- .../justMUSIC/lib/screens/feed_screen.dart | 49 +++++++++++++------ .../lib/view_model/PostViewModel.dart | 4 +- Sources/justMUSIC/pubspec.lock | 8 +++ Sources/justMUSIC/pubspec.yaml | 1 + 6 files changed, 54 insertions(+), 56 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 1d44074..d31b78d 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -156,13 +156,6 @@ - - - - - - @@ -191,6 +184,13 @@ + + + + + + @@ -324,13 +324,6 @@ - - - - - - @@ -527,13 +520,6 @@ - - - - - - @@ -562,13 +548,6 @@ - - - - - - @@ -681,13 +660,6 @@ - - - - - - @@ -850,6 +822,7 @@ + diff --git a/Sources/justMUSIC/lib/components/post_component.dart b/Sources/justMUSIC/lib/components/post_component.dart index d6c5bd4..4d1de01 100644 --- a/Sources/justMUSIC/lib/components/post_component.dart +++ b/Sources/justMUSIC/lib/components/post_component.dart @@ -1,7 +1,4 @@ -import 'dart:js_interop'; - import 'package:auto_size_text/auto_size_text.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -338,7 +335,7 @@ class _PostComponentState extends State with TickerProviderStateM fit: BoxFit.fitHeight, width: double.infinity, ), - widget.post.description.isNull + widget.post.description == null ? Container() : Padding( padding: EdgeInsets.all(15), diff --git a/Sources/justMUSIC/lib/screens/feed_screen.dart b/Sources/justMUSIC/lib/screens/feed_screen.dart index 880cfe9..82026ff 100644 --- a/Sources/justMUSIC/lib/screens/feed_screen.dart +++ b/Sources/justMUSIC/lib/screens/feed_screen.dart @@ -1,5 +1,4 @@ import 'package:circular_reveal_animation/circular_reveal_animation.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -49,6 +48,14 @@ class _FeedScreenState extends State with SingleTickerProviderStateM ); } + Future _refresh() async { + print("refresh"); + discoveryFeed = await MyApp.postViewModel.getBestPosts(); + setState(() { + displayFeed = discoveryFeed.reversed.toList(); + }); + } + void changeFeed(bool choice) { // Mettez ici le code pour l'action que vous souhaitez effectuer avec le paramètre if (choice) { @@ -120,9 +127,14 @@ class _FeedScreenState extends State with SingleTickerProviderStateM index: index, ), Container(height: 5), - Text('${displayFeed[index].description ?? ""}', - style: GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w200)), - Container(height: 20), + displayFeed[index].description == null + ? Container() + : Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Text('${displayFeed[index].description ?? ""}', + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w200)), + ), Align( child: RichText( text: TextSpan( @@ -275,18 +287,23 @@ class _FeedScreenState extends State with SingleTickerProviderStateM 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), - ); - }, + child: RefreshIndicator( + displacement: 20, + triggerMode: RefreshIndicatorTriggerMode.onEdge, + onRefresh: _refresh, + 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), + ); + }, + ), )), ), ), diff --git a/Sources/justMUSIC/lib/view_model/PostViewModel.dart b/Sources/justMUSIC/lib/view_model/PostViewModel.dart index 8bd6d55..9c5aee8 100644 --- a/Sources/justMUSIC/lib/view_model/PostViewModel.dart +++ b/Sources/justMUSIC/lib/view_model/PostViewModel.dart @@ -34,7 +34,7 @@ class PostViewModel { throw new Error(); } - getBestPosts() async { + Future> getBestPosts() async { try { var responseData = await _postService.getPopularPosts(); List ids = []; @@ -47,8 +47,10 @@ class PostViewModel { for (int i = 0; i < _bestPosts.length; i++) { _bestPosts[i].music = musics[i]; } + return _bestPosts; } catch (e) { print(e); + return []; } } diff --git a/Sources/justMUSIC/pubspec.lock b/Sources/justMUSIC/pubspec.lock index 3d4cd76..6de85fb 100644 --- a/Sources/justMUSIC/pubspec.lock +++ b/Sources/justMUSIC/pubspec.lock @@ -209,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.2" + custom_refresh_indicator: + dependency: "direct main" + description: + name: custom_refresh_indicator + sha256: "65a463f09623f6baf75e45e0c9034e9304810be3f5dfb00a54edde7252f4a524" + url: "https://pub.dev" + source: hosted + version: "2.2.1" fake_async: dependency: transitive description: diff --git a/Sources/justMUSIC/pubspec.yaml b/Sources/justMUSIC/pubspec.yaml index 730fa0d..ab36a1a 100644 --- a/Sources/justMUSIC/pubspec.yaml +++ b/Sources/justMUSIC/pubspec.yaml @@ -68,6 +68,7 @@ dependencies: flutter_countdown_timer: ^4.1.0 intl: ^0.18.1 lottie: ^2.5.0 + custom_refresh_indicator: ^2.2.1 dev_dependencies: flutter_test: