fix: loading song covers correctly

This commit is contained in:
Matyáš Caras 2024-05-30 11:37:22 +02:00
parent b1db0059eb
commit 664dc7fd27
Signed by: hernik
GPG key ID: 2A3175F98820C5C6
2 changed files with 82 additions and 30 deletions

View file

@ -201,7 +201,9 @@ class AudioPlayerService {
initialPosition: Duration.zero, initialPosition: Duration.zero,
); );
songNotifier.value = _songList[queuePast.length];
playerKey.currentState?.update(); playerKey.currentState?.update();
await _setColorScheme();
resume(); resume();
} }
} }

View file

@ -10,11 +10,11 @@ import 'package:responsive_sizer/responsive_sizer.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
import 'package:text_scroll/text_scroll.dart'; import 'package:text_scroll/text_scroll.dart';
/// The player widget /// The player control widget
/// ///
/// Showcases the playing song's details and features playback controls /// Showcases the playing song's details and features playback controls
class Player extends StatefulWidget { class Player extends StatefulWidget {
/// The player widget /// The player control widget
/// ///
/// Showcases the playing song's details and features playback controls /// Showcases the playing song's details and features playback controls
const Player({super.key}); const Player({super.key});
@ -54,25 +54,25 @@ class PlayerState extends State<Player> {
controller: s, controller: s,
child: Column( child: Column(
children: [ children: [
AnimatedOpacity( ClipRRect(
opacity: _showFullControls ? 0 : 1, borderRadius: BorderRadius.circular(8),
duration: const Duration(milliseconds: 300), child: GestureDetector(
child: ClipRRect( onTap: () {
borderRadius: BorderRadius.circular(8), _sheetController.animateTo(
child: GestureDetector( (_sheetController.size == 1) ? 0.1 : 1,
onTap: () { duration: const Duration(milliseconds: 300),
_sheetController.animateTo( curve: Curves.easeIn,
(_sheetController.size == 1) ? 0.1 : 1, );
duration: const Duration(milliseconds: 300), },
curve: Curves.easeIn, child: Container(
); color: Theme.of(context).colorScheme.primaryContainer,
}, height: 10.h,
child: Container( width: 100.w,
color: Theme.of(context).colorScheme.primaryContainer, child: AnimatedOpacity(
height: 10.h, opacity: _showFullControls ? 0 : 1,
width: 100.w, duration: const Duration(milliseconds: 300),
child: Padding( child: Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(16),
child: ValueListenableBuilder<Song?>( child: ValueListenableBuilder<Song?>(
valueListenable: songNotifier, valueListenable: songNotifier,
builder: (c, t, w) { builder: (c, t, w) {
@ -82,7 +82,7 @@ class PlayerState extends State<Player> {
height: 10.h, height: 10.h,
width: 10.h, width: 10.h,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(16),
child: ClipRRect( child: ClipRRect(
child: (t == null) child: (t == null)
? ColoredBox( ? ColoredBox(
@ -224,18 +224,18 @@ class PlayerState extends State<Player> {
width: 80.w, width: 80.w,
height: 80.w, height: 80.w,
child: ClipRRect( child: ClipRRect(
// borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
child: (AudioPlayerService().song == null) child: (AudioPlayerService().song == null)
? ColoredBox( ? ColoredBox(
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.primaryContainer, .secondaryContainer,
child: Center( child: Center(
child: Icon( child: Icon(
Icons.music_note, Icons.music_note,
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.onPrimaryContainer, .onSecondaryContainer,
), ),
), ),
) )
@ -258,13 +258,13 @@ class PlayerState extends State<Player> {
return ColoredBox( return ColoredBox(
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.primaryContainer, .secondaryContainer,
child: Center( child: Center(
child: Icon( child: Icon(
Icons.music_note, Icons.music_note,
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.onPrimaryContainer, .onSecondaryContainer,
), ),
), ),
); );
@ -297,7 +297,7 @@ class PlayerState extends State<Player> {
), ),
SizedBox( SizedBox(
width: 70.w, width: 70.w,
height: 50, height: 30,
child: AutoSizeText( child: AutoSizeText(
AudioPlayerService().song?.artistName ?? "Nobody", AudioPlayerService().song?.artistName ?? "Nobody",
style: TextStyle(fontSize: 16.sp), style: TextStyle(fontSize: 16.sp),
@ -310,9 +310,6 @@ class PlayerState extends State<Player> {
), ),
), ),
), ),
const SizedBox(
height: 10,
),
SizedBox( SizedBox(
width: 60.w, width: 60.w,
height: 40, height: 40,
@ -342,6 +339,59 @@ class PlayerState extends State<Player> {
], ],
), ),
), ),
const SizedBox(
height: 10,
),
SizedBox(
width: 60.w,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
AudioPlayerService().previous();
},
icon: const Icon(
Icons.skip_previous,
size: 36,
),
),
IconButton(
onPressed: () async {
if (AudioPlayerService().song == null) {
return;
}
if (AudioPlayerService().isPlaying) {
await AudioPlayerService().pause();
} else {
AudioPlayerService().resume();
}
setState(() {});
},
icon: AnimatedCrossFade(
firstChild: const Icon(
Icons.play_arrow,
size: 36, // TODO: adapt to display size
),
secondChild: const Icon(Icons.pause, size: 36),
crossFadeState: (AudioPlayerService().isPlaying)
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
duration: const Duration(milliseconds: 300),
),
),
IconButton(
onPressed: () {
AudioPlayerService().next();
},
icon: const Icon(
Icons.skip_next,
size: 36,
),
),
],
),
),
], ],
), ),
), ),