From 3ca01ef1474a4c7ee5221128942c4c47cdbd0b70 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 29 Aug 2024 22:39:54 +0800 Subject: [PATCH] :bug: Bug fixes and optimization --- lib/screens/library/view.dart | 19 +++++++++++++------ lib/widgets/lyrics/synced_lyrics.dart | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/screens/library/view.dart b/lib/screens/library/view.dart index fec0ff0..1081991 100644 --- a/lib/screens/library/view.dart +++ b/lib/screens/library/view.dart @@ -3,6 +3,7 @@ import 'package:get/get.dart'; import 'package:rhythm_box/providers/auth.dart'; import 'package:rhythm_box/widgets/no_login_fallback.dart'; import 'package:rhythm_box/widgets/playlist/user_playlist_list.dart'; +import 'package:rhythm_box/widgets/sized_container.dart'; class LibraryScreen extends StatefulWidget { const LibraryScreen({super.key}); @@ -18,16 +19,22 @@ class _LibraryScreenState extends State { Widget build(BuildContext context) { return Material( color: Theme.of(context).colorScheme.surface, - child: SafeArea( - child: Obx(() { + child: Scaffold( + appBar: AppBar( + title: const Text('Library'), + centerTitle: MediaQuery.of(context).size.width >= 720, + ), + body: Obx(() { if (_authenticate.auth.value == null) { return const NoLoginFallback(); } - return const Column( - children: [ - Expanded(child: UserPlaylistList()), - ], + return const CenteredContainer( + child: Column( + children: [ + Expanded(child: UserPlaylistList()), + ], + ), ); }), ), diff --git a/lib/widgets/lyrics/synced_lyrics.dart b/lib/widgets/lyrics/synced_lyrics.dart index a2ace7b..6a38f3f 100644 --- a/lib/widgets/lyrics/synced_lyrics.dart +++ b/lib/widgets/lyrics/synced_lyrics.dart @@ -48,10 +48,31 @@ class _SyncedLyricsState extends State { Color get _unFocusColor => Theme.of(context).colorScheme.onSurface.withOpacity(0.5); + void _syncLyricsProgress() { + for (var idx = 0; idx < _lyric!.lyrics.length; idx++) { + final lyricSlice = _lyric!.lyrics[idx]; + final lyricNextSlice = + idx + 1 < _lyric!.lyrics.length ? _lyric!.lyrics[idx + 1] : null; + final isActive = _playback.durationCurrent.value.inSeconds >= + lyricSlice.time.inSeconds && + (lyricNextSlice == null || + lyricNextSlice.time.inSeconds > + _playback.durationCurrent.value.inSeconds); + if (isActive) { + _autoScrollController.scrollToIndex( + idx, + preferPosition: AutoScrollPosition.middle, + ); + } + } + } + @override void initState() { super.initState(); - _pullLyrics(); + _pullLyrics().then((_) { + _syncLyricsProgress(); + }); _subscriptions = [ _playback.state.listen((value) { if (value.activeTrack == null) return;