Skip to content

Commit

Permalink
feat(mini_player): show/hide lyrics #851
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 21, 2023
1 parent 7818574 commit dcbb156
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
1 change: 1 addition & 0 deletions lib/collections/spotube_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ abstract class SpotubeIcons {
static const trash = FeatherIcons.trash2;
static const clock = FeatherIcons.clock;
static const lyrics = Icons.lyrics_rounded;
static const lyricsOff = Icons.lyrics_outlined;
static const logout = FeatherIcons.logOut;
static const login = FeatherIcons.logIn;
static const dashboard = FeatherIcons.grid;
Expand Down
83 changes: 55 additions & 28 deletions lib/pages/lyrics/mini_lyrics.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:palette_generator/palette_generator.dart';
Expand Down Expand Up @@ -32,6 +33,7 @@ class MiniLyricsPage extends HookConsumerWidget {

final areaActive = useState(false);
final hoverMode = useState(true);
final showLyrics = useState(true);

useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
Expand Down Expand Up @@ -82,17 +84,41 @@ class MiniLyricsPage extends HookConsumerWidget {
child: Sidebar.brandLogo(),
),
const Spacer(),
SizedBox(
height: 30,
child: TabBar(
tabs: [
Tab(text: context.l10n.synced),
Tab(text: context.l10n.plain),
],
isScrollable: true,
if (showLyrics.value)
SizedBox(
height: 30,
child: TabBar(
tabs: [
Tab(text: context.l10n.synced),
Tab(text: context.l10n.plain),
],
isScrollable: true,
),
),
),
const Spacer(),
IconButton(
tooltip: context.l10n.lyrics,
icon: showLyrics.value
? const Icon(SpotubeIcons.lyrics)
: const Icon(SpotubeIcons.lyricsOff),
style: ButtonStyle(
foregroundColor: showLyrics.value
? MaterialStateProperty.all(
theme.colorScheme.primary)
: null,
),
onPressed: () async {
showLyrics.value = !showLyrics.value;
areaActive.value = true;
hoverMode.value = false;

await DesktopTools.window.setSize(
showLyrics.value
? const Size(400, 500)
: const Size(400, 150),
);
},
),
IconButton(
tooltip: context.l10n.show_hide_ui_on_hover,
icon: hoverMode.value
Expand All @@ -105,9 +131,7 @@ class MiniLyricsPage extends HookConsumerWidget {
: null,
),
onPressed: () async {
if (!hoverMode.value == true) {
areaActive.value = true;
}
areaActive.value = true;
hoverMode.value = !hoverMode.value;
},
),
Expand Down Expand Up @@ -150,22 +174,25 @@ class MiniLyricsPage extends HookConsumerWidget {
playlistQueue.activeTrack!.name!,
style: theme.textTheme.titleMedium,
),
Expanded(
child: TabBarView(
children: [
SyncedLyrics(
palette: PaletteColor(theme.colorScheme.background, 0),
isModal: true,
defaultTextZoom: 65,
),
PlainLyrics(
palette: PaletteColor(theme.colorScheme.background, 0),
isModal: true,
defaultTextZoom: 65,
),
],
),
),
if (showLyrics.value)
Expanded(
child: TabBarView(
children: [
SyncedLyrics(
palette: PaletteColor(theme.colorScheme.background, 0),
isModal: true,
defaultTextZoom: 65,
),
PlainLyrics(
palette: PaletteColor(theme.colorScheme.background, 0),
isModal: true,
defaultTextZoom: 65,
),
],
),
)
else
const Gap(20),
AnimatedCrossFade(
crossFadeState: areaActive.value
? CrossFadeState.showFirst
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/lyrics/synced_lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SyncedLyrics extends HookConsumerWidget {
final lyricSlice = lyricValue.lyrics[index];
final isActive = lyricSlice.time.inSeconds == currentTime;

if (isActive && isUnSyncLyric == true) {
if (isActive) {
controller.scrollToIndex(
index,
preferPosition: AutoScrollPosition.middle,
Expand Down

0 comments on commit dcbb156

Please sign in to comment.