Skip to content

Commit

Permalink
Make non-square album art display better on "Albums" (#579)
Browse files Browse the repository at this point in the history
Fixes #200
  • Loading branch information
Feichtmeier authored Mar 11, 2024
1 parent 13d4f89 commit 0755cdb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
Binary file added assets/images/media-optical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion lib/src/common/audio_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class AudioCard extends StatefulWidget {
this.width,
this.color,
this.showBorder = true,
this.background,
});
final Widget? image;
final Widget? background;
final void Function()? onTap;
final void Function()? onPlay;
final Widget? bottom;
Expand Down Expand Up @@ -56,7 +58,8 @@ class _AudioCardState extends State<AudioCard> {
borderRadius: BorderRadius.circular(10),
child: Stack(
children: [
if (widget.image == null)
if (widget.background != null) widget.background!,
if (widget.image == null && widget.background != null)
Shimmer.fromColors(
baseColor: light ? kCardColorLight : kCardColorDark,
highlightColor: light
Expand Down
18 changes: 13 additions & 5 deletions lib/src/local_audio/album_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand Down Expand Up @@ -52,13 +53,20 @@ class AlbumPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final model = ref.read(localAudioModelProvider);
final image = album.firstOrNull?.pictureData != null
? Image.memory(
album.firstOrNull!.pictureData!,
final pictureData =
album.firstWhereOrNull((e) => e.pictureData != null)?.pictureData;

final image = Stack(
children: [
Image.asset('assets/images/media-optical.png'),
if (pictureData != null)
Image.memory(
pictureData,
fit: BoxFit.fitHeight,
filterQuality: FilterQuality.medium,
)
: null;
),
],
);

void onArtistTap(text) {
final artistName = album.firstOrNull?.artist;
Expand Down
22 changes: 10 additions & 12 deletions lib/src/local_audio/album_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../build_context_x.dart';
import '../../common.dart';
import '../../constants.dart';
import '../../library.dart';
Expand All @@ -25,8 +24,6 @@ class AlbumsView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = context.t;

if (albums == null) {
return const Center(
child: Progress(),
Expand Down Expand Up @@ -56,20 +53,20 @@ class AlbumsView extends ConsumerWidget {
final albumAudios = model.findAlbum(audio);

final image = audio.pictureData == null
? Center(
child: Icon(
Iconz().musicNote,
size: 70,
color: theme.hintColor,
),
)
? null
: Image.memory(
audio.pictureData!,
fit: BoxFit.cover,
fit: BoxFit.fitHeight,
height: kAudioCardDimension,
filterQuality: FilterQuality.medium,
);

final fallback = Image.asset(
'assets/images/media-optical.png',
height: kAudioCardDimension,
width: kAudioCardDimension,
);

return AudioCard(
bottom: Align(
alignment: Alignment.bottomCenter,
Expand All @@ -79,7 +76,8 @@ class AlbumsView extends ConsumerWidget {
: audio.album ?? '',
),
),
image: image,
image: image ?? fallback,
background: fallback,
onTap: id == null || albumAudios == null
? null
: () => Navigator.of(context).push(
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ flutter:
uses-material-design: true
assets:
- snap/gui/musicpod.png
- assets/images/media-optical.png

dependency_overrides:
intl: 0.19.0

0 comments on commit 0755cdb

Please sign in to comment.