Skip to content
Snippets Groups Projects
Commit 61036409 authored by Erik Hinkelmanns's avatar Erik Hinkelmanns
Browse files

- fixed image bug for music bar

parent c039ef05
No related branches found
No related tags found
No related merge requests found
......@@ -118,7 +118,7 @@ class HomePage extends StatelessWidget {
fontWeight: FontWeight.bold,
color: Colors.black)),
MusicPlayerState.of(context).connected
? spotifyImageWidget(track.imageUri)
? MusicPlayerState.of(context).spotifyImageWidget()
: const Text('Connect to see an image...'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
......@@ -157,31 +157,7 @@ class HomePage extends StatelessWidget {
);
}
Widget spotifyImageWidget(ImageUri image) {
return FutureBuilder(
future: SpotifySdk.getImage(
imageUri: image,
dimension: ImageDimension.large,
),
builder: (BuildContext context, AsyncSnapshot<Uint8List?> snapshot) {
if (snapshot.hasData) {
return Image.memory(snapshot.data!);
} else if (snapshot.hasError) {
setStatus(snapshot.error.toString());
return SizedBox(
width: ImageDimension.large.value.toDouble(),
height: ImageDimension.large.value.toDouble(),
child: const Center(child: Text('Error getting image')),
);
} else {
return SizedBox(
width: ImageDimension.large.value.toDouble(),
height: ImageDimension.large.value.toDouble(),
child: const Center(child: Text('Getting image...')),
);
}
});
}
Future getPlayerState() async {
try {
......
......@@ -109,8 +109,7 @@ class _HUDState extends State<HUD> {
},
),
],
),
);
));
}
}
......@@ -123,11 +122,9 @@ class MusicBar extends StatelessWidget {
Widget build(BuildContext context) {
return StreamBuilder<PlayerState>(
stream: SpotifySdk.subscribePlayerState(),
builder: (BuildContext context,
AsyncSnapshot<PlayerState> snapshot) {
builder: (BuildContext context, AsyncSnapshot<PlayerState> snapshot) {
var track = snapshot.data?.track;
MusicPlayerState.of(context).currentTrackImageUri =
track?.imageUri;
MusicPlayerState.of(context).currentTrackImageUri = track?.imageUri;
var playerState = snapshot.data;
if (playerState == null || track == null) {
return const Center(
......@@ -139,7 +136,7 @@ class MusicBar extends StatelessWidget {
color: Colors.grey,
child: Row(
children: [
MusicPlayerState.of(context).spotifyImageWidget(),
MusicPlayerState.of(context).albumImage,
playerState.isPaused
? const IconButton(
icon: Icon(Icons.play_arrow_outlined),
......
......@@ -14,6 +14,7 @@ class MusicPlayerState extends InheritedWidget {
bool connected = false;
StreamController<void> rebuildStream = new StreamController.broadcast();
late ImageUri? currentTrackImageUri;
late Image albumImage;
static MusicPlayerState? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<MusicPlayerState>();
......@@ -76,7 +77,8 @@ class MusicPlayerState extends InheritedWidget {
),
builder: (BuildContext context, AsyncSnapshot<Uint8List?> snapshot) {
if (snapshot.hasData) {
return Image.memory(snapshot.data!);
albumImage = Image.memory(snapshot.data!);
return albumImage;
} else if (snapshot.hasError) {
setStatus(snapshot.error.toString());
return SizedBox(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment