From 6967675fea3b1cfa53dc48503546a63919e5241d Mon Sep 17 00:00:00 2001 From: Chaphasilor Date: Fri, 3 May 2024 18:24:03 +0200 Subject: [PATCH] fix floating action buttons on music screen not adhering to tab order - there still seems to be some issue when switching from playlists tab to albums, there the FAB stays hidden for some reason... --- lib/screens/music_screen.dart | 30 ++++++++++++--------------- lib/screens/tabs_settings_screen.dart | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/screens/music_screen.dart b/lib/screens/music_screen.dart index 5eb0b8f5e..b23525638 100644 --- a/lib/screens/music_screen.dart +++ b/lib/screens/music_screen.dart @@ -97,14 +97,10 @@ class _MusicScreenState extends ConsumerState super.dispose(); } - FloatingActionButton? getFloatingActionButton() { - var tabList = FinampSettingsHelper.finampSettings.showTabs.entries - .where((element) => element.value) - .map((e) => e.key) - .toList(); + FloatingActionButton? getFloatingActionButton(List sortedTabs) { // Show the floating action button only on the albums, artists, generes and songs tab. - if (_tabController!.index == tabList.indexOf(TabContentType.songs)) { + if (_tabController!.index == sortedTabs.indexOf(TabContentType.songs)) { return FloatingActionButton( tooltip: AppLocalizations.of(context)!.shuffleAll, onPressed: () async { @@ -118,7 +114,7 @@ class _MusicScreenState extends ConsumerState child: const Icon(Icons.shuffle), ); } else if (_tabController!.index == - tabList.indexOf(TabContentType.artists)) { + sortedTabs.indexOf(TabContentType.artists)) { return FloatingActionButton( tooltip: AppLocalizations.of(context)!.startMix, onPressed: () async { @@ -137,7 +133,7 @@ class _MusicScreenState extends ConsumerState }, child: const Icon(Icons.explore)); } else if (_tabController!.index == - tabList.indexOf(TabContentType.albums)) { + sortedTabs.indexOf(TabContentType.albums)) { return FloatingActionButton( tooltip: AppLocalizations.of(context)!.startMix, onPressed: () async { @@ -155,7 +151,7 @@ class _MusicScreenState extends ConsumerState }, child: const Icon(Icons.explore)); } else if (_tabController!.index == - tabList.indexOf(TabContentType.genres)) { + sortedTabs.indexOf(TabContentType.genres)) { return FloatingActionButton( tooltip: AppLocalizations.of(context)!.startMix, onPressed: () async { @@ -193,12 +189,12 @@ class _MusicScreenState extends ConsumerState // Get the tabs from the user's tab order, and filter them to only // include enabled tabs - final tabs = finampSettings!.tabOrder.where( + final sortedTabs = finampSettings!.tabOrder.where( (e) => FinampSettingsHelper.finampSettings.showTabs[e] ?? false); - if (tabs.length != _tabController?.length) { + if (sortedTabs.length != _tabController?.length) { _musicScreenLogger.info( - "Rebuilding MusicScreen tab controller (${tabs.length} != ${_tabController?.length})"); + "Rebuilding MusicScreen tab controller (${sortedTabs.length} != ${_tabController?.length})"); _buildTabController(); } @@ -231,7 +227,7 @@ class _MusicScreenState extends ConsumerState AppLocalizations.of(context)!.music), bottom: TabBar( controller: _tabController, - tabs: tabs + tabs: sortedTabs .map((tabType) => Tab( text: tabType.toLocalisedString(context).toUpperCase(), @@ -261,10 +257,10 @@ class _MusicScreenState extends ConsumerState ] : [ SortOrderButton( - tabs.elementAt(_tabController!.index), + sortedTabs.elementAt(_tabController!.index), ), SortByMenuButton( - tabs.elementAt(_tabController!.index), + sortedTabs.elementAt(_tabController!.index), ), if (finampSettings.isOffline) IconButton( @@ -307,7 +303,7 @@ class _MusicScreenState extends ConsumerState right: FinampSettingsHelper.finampSettings.showFastScroller ? 24.0 : 8.0), - child: getFloatingActionButton(), + child: getFloatingActionButton(sortedTabs.toList()), ), body: TabBarView( controller: _tabController, @@ -315,7 +311,7 @@ class _MusicScreenState extends ConsumerState ? const NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(), dragStartBehavior: DragStartBehavior.down, - children: tabs + children: sortedTabs .map((tabType) => MusicScreenTabView( tabContentType: tabType, searchTerm: searchQuery, diff --git a/lib/screens/tabs_settings_screen.dart b/lib/screens/tabs_settings_screen.dart index 30292339f..eaaae144d 100644 --- a/lib/screens/tabs_settings_screen.dart +++ b/lib/screens/tabs_settings_screen.dart @@ -55,7 +55,7 @@ class _TabsSettingsScreenState extends State { newIndex -= 1; } - final currentTabOrder = FinampSettingsHelper.finampSettings.tabOrder; + var currentTabOrder = FinampSettingsHelper.finampSettings.tabOrder; // move all values below newIndex down by one final oldTab = currentTabOrder[oldIndex];