Skip to content

Commit

Permalink
Apply decorations directly in album image (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmshrv committed May 30, 2024
1 parent e936ccc commit b08b211
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
12 changes: 5 additions & 7 deletions lib/components/PlayerScreen/player_screen_album_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ class PlayerScreenAlbumImage extends ConsumerWidget {
left: horizontalPadding,
right: horizontalPadding,
),
child: Container(
child: AlbumImage(
imageListenable: currentAlbumImageProvider,
borderRadius: BorderRadius.circular(8.0),
// Load player cover at max size to allow more seamless scaling
autoScale: false,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
Expand All @@ -108,12 +112,6 @@ class PlayerScreenAlbumImage extends ConsumerWidget {
)
],
),
child: AlbumImage(
imageListenable: currentAlbumImageProvider,
borderRadius: BorderRadius.circular(8.0),
// Load player cover at max size to allow more seamless scaling
autoScale: false,
),
),
);
}),
Expand Down
43 changes: 29 additions & 14 deletions lib/components/album_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AlbumImage extends ConsumerWidget {
this.placeholderBuilder,
this.disabled = false,
this.autoScale = true,
this.decoration,
});

/// The item to get an image for.
Expand All @@ -49,6 +50,11 @@ class AlbumImage extends ConsumerWidget {
/// Whether to automatically scale the image to the size of the widget.
final bool autoScale;

/// The decoration to use for the album image. This is defined in AlbumImage
/// instead of being used as a separate widget so that non-square images don't
/// look incorrect due to AlbumImage having an aspect ratio of 1:1
final Decoration? decoration;

static final defaultBorderRadius = BorderRadius.circular(4);

@override
Expand All @@ -58,9 +64,12 @@ class AlbumImage extends ConsumerWidget {
if ((item == null || item!.imageId == null) && imageListenable == null) {
return ClipRRect(
borderRadius: borderRadius,
child: const AspectRatio(
child: AspectRatio(
aspectRatio: 1,
child: _AlbumImageErrorPlaceholder(),
child: Container(
decoration: decoration,
child: const _AlbumImageErrorPlaceholder(),
),
),
);
}
Expand Down Expand Up @@ -96,18 +105,24 @@ class AlbumImage extends ConsumerWidget {
}
}

var image = BareAlbumImage(
imageListenable: imageListenable ??
albumImageProvider(AlbumImageRequest(
item: item!,
maxWidth: physicalWidth,
maxHeight: physicalHeight,
)).select((value) => (value, item?.blurHash)),
imageProviderCallback: themeCallback == null
? null
: (image) => themeCallback!(
FinampTheme.fromImageDeferred(image, item?.blurHash)),
placeholderBuilder: placeholderBuilder);
var image = Center(
// This Center stops the container from expanding
child: Container(
decoration: decoration,
child: BareAlbumImage(
imageListenable: imageListenable ??
albumImageProvider(AlbumImageRequest(
item: item!,
maxWidth: physicalWidth,
maxHeight: physicalHeight,
)).select((value) => (value, item?.blurHash)),
imageProviderCallback: themeCallback == null
? null
: (image) => themeCallback!(
FinampTheme.fromImageDeferred(image, item?.blurHash)),
placeholderBuilder: placeholderBuilder),
),
);
return disabled
? Opacity(
opacity: 0.75,
Expand Down

0 comments on commit b08b211

Please sign in to comment.