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,
);
songNotifier.value = _songList[queuePast.length];
playerKey.currentState?.update();
await _setColorScheme();
resume();
}
}

View file

@ -10,11 +10,11 @@ import 'package:responsive_sizer/responsive_sizer.dart';
import 'package:shimmer/shimmer.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
class Player extends StatefulWidget {
/// The player widget
/// The player control widget
///
/// Showcases the playing song's details and features playback controls
const Player({super.key});
@ -54,25 +54,25 @@ class PlayerState extends State<Player> {
controller: s,
child: Column(
children: [
AnimatedOpacity(
opacity: _showFullControls ? 0 : 1,
duration: const Duration(milliseconds: 300),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: GestureDetector(
onTap: () {
_sheetController.animateTo(
(_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,
width: 100.w,
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: GestureDetector(
onTap: () {
_sheetController.animateTo(
(_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,
width: 100.w,
child: AnimatedOpacity(
opacity: _showFullControls ? 0 : 1,
duration: const Duration(milliseconds: 300),
child: Padding(
padding: const EdgeInsets.all(8),
padding: const EdgeInsets.all(16),
child: ValueListenableBuilder<Song?>(
valueListenable: songNotifier,
builder: (c, t, w) {
@ -82,7 +82,7 @@ class PlayerState extends State<Player> {
height: 10.h,
width: 10.h,
child: Padding(
padding: const EdgeInsets.all(8),
padding: const EdgeInsets.all(16),
child: ClipRRect(
child: (t == null)
? ColoredBox(
@ -224,18 +224,18 @@ class PlayerState extends State<Player> {
width: 80.w,
height: 80.w,
child: ClipRRect(
// borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(16),
child: (AudioPlayerService().song == null)
? ColoredBox(
color: Theme.of(context)
.colorScheme
.primaryContainer,
.secondaryContainer,
child: Center(
child: Icon(
Icons.music_note,
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
.onSecondaryContainer,
),
),
)
@ -258,13 +258,13 @@ class PlayerState extends State<Player> {
return ColoredBox(
color: Theme.of(context)
.colorScheme
.primaryContainer,
.secondaryContainer,
child: Center(
child: Icon(
Icons.music_note,
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
.onSecondaryContainer,
),
),
);
@ -297,7 +297,7 @@ class PlayerState extends State<Player> {
),
SizedBox(
width: 70.w,
height: 50,
height: 30,
child: AutoSizeText(
AudioPlayerService().song?.artistName ?? "Nobody",
style: TextStyle(fontSize: 16.sp),
@ -310,9 +310,6 @@ class PlayerState extends State<Player> {
),
),
),
const SizedBox(
height: 10,
),
SizedBox(
width: 60.w,
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,
),
),
],
),
),
],
),
),