From 17b6826429fe48c926d87f5beee5e5ebf799f936 Mon Sep 17 00:00:00 2001
From: Erik Hinkelmanns <erik.hinkelmanns@stud.hs-hannover.de>
Date: Mon, 23 Jan 2023 19:22:00 +0100
Subject: [PATCH] - when there is no song in que the user will be redirected to
 the search page

---
 lib/homepage.dart                 |  8 ++++++--
 lib/main.dart                     | 12 ++++++------
 lib/widgets/musicPlayerState.dart |  6 ------
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/lib/homepage.dart b/lib/homepage.dart
index ecf9f42..3fe37e4 100644
--- a/lib/homepage.dart
+++ b/lib/homepage.dart
@@ -17,7 +17,8 @@ void printErr(String msg) {
 }
 
 class HomePage extends StatelessWidget {
-  const HomePage({super.key});
+  final pageController;
+  const HomePage({super.key, this.pageController});
 
   @override
   Widget build(BuildContext context) {
@@ -95,7 +96,10 @@ class HomePage extends StatelessWidget {
           textColor: Colors.white,
           shape: const CircleBorder(),
           onPressed: (){
-              play().then((value) => MusicPlayerState.of(context).rebuildPage());
+              pageController.animateToPage(2,
+                duration: const Duration(milliseconds: 500),
+                curve: Curves.ease);
+              //_title = _titleList[2];
           },
           child: const Icon(
             Icons.play_arrow_rounded,
diff --git a/lib/main.dart b/lib/main.dart
index b3943b9..276c278 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -50,7 +50,7 @@ class _HUDState extends State<HUD> {
   int _currentIndex = 0;
   final List<String> _titleList = ["Player", "Mood", "Search"];
   String _title = "";
-  PageController _pageController = PageController(initialPage: 0);
+  final PageController _pageController = PageController(initialPage: 0);
 
   @override
   void initState() {
@@ -71,10 +71,10 @@ class _HUDState extends State<HUD> {
               _title = _titleList[newIndex];
             });
           },
-          children: const [
-            HomePage(),
-            StateMoodPage(),
-            StateSearcgPage(),
+          children:  [
+            HomePage(pageController: _pageController,),
+            const StateMoodPage(),
+            const StateSearcgPage(),
           ],
         ),
         bottomNavigationBar: Column(
@@ -93,7 +93,7 @@ class _HUDState extends State<HUD> {
                 ),
                 BottomNavigationBarItem(icon: Icon(Icons.mood), label: "Moods"),
                 BottomNavigationBarItem(
-                    icon: Icon(Icons.search), label: "Suchen"),
+                    icon: Icon(Icons.search), label: "Search"),
               ],
               onTap: (newIndex) {
                 _pageController.animateToPage(newIndex,
diff --git a/lib/widgets/musicPlayerState.dart b/lib/widgets/musicPlayerState.dart
index b5abddd..5903ce9 100644
--- a/lib/widgets/musicPlayerState.dart
+++ b/lib/widgets/musicPlayerState.dart
@@ -34,12 +34,6 @@ class MusicPlayerState extends InheritedWidget {
     rebuildStream.sink.add(null);
   }
 
-  void rebuildPage() async {
-    playerState = await getPlayerState();
-    currentTrackImageUri = playerState?.track?.imageUri;
-    rebuildStream.sink.add(null);
-  }
-
   void updatePlayerState() async {
     playerState = await getPlayerState();
     currentTrackImageUri = playerState?.track?.imageUri;
-- 
GitLab