mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
Desktop track and album lists now load with placeholder rows that use the track table's columns, row height and quality column, so content does not jump when it arrives. The track table geometry and the artist discography tile size move to shared helpers that the placeholders reuse.
162 lines
6.1 KiB
Dart
162 lines
6.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mornye/utils/desktop_platform.dart';
|
|
|
|
/// Keeps touch-first tablets on the bottom navigation used by phones. A rail
|
|
/// is reserved for genuinely desktop-width windows; the old 600dp threshold
|
|
/// made an iPad portrait layout look like a shrunken desktop app.
|
|
const double navigationRailBreakpoint = 1440;
|
|
|
|
/// Material's expanded window class. Landscape tablets switch the Material
|
|
/// theme to a navigation rail and Mornye to compact, centered chrome; portrait
|
|
/// tablets stay below it.
|
|
const double expandedLayoutBreakpoint = 840;
|
|
const double defaultWideContentMaxWidth = 840;
|
|
|
|
bool useNavigationRailForWidth(double width) =>
|
|
width >= navigationRailBreakpoint;
|
|
|
|
/// The Material theme follows Material's expanded window class.
|
|
bool useMaterialNavigationRailForWidth(double width) =>
|
|
width >= expandedLayoutBreakpoint;
|
|
|
|
/// Explicit horizontal safe spacing for controls drawn in full-bleed detail
|
|
/// headers. iOS reports no left/right safe-area inset in portrait, so toolbar
|
|
/// buttons otherwise land only a few pixels from the device edge. Filled
|
|
/// expressive circles need the same breathing room on Android.
|
|
double detailHeaderEdgeInset(BuildContext context) {
|
|
final platform = Theme.of(context).platform;
|
|
return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS
|
|
? 12
|
|
: 8;
|
|
}
|
|
|
|
/// Visual scale for touch-first tablet surfaces. Large iPads have enough
|
|
/// pixels to make an unscaled phone density feel miniature, especially when
|
|
/// Simulator shrinks the whole device to fit a desktop display. Desktop
|
|
/// windows keep native density at every size.
|
|
double adaptiveUiScaleForSize(Size size) {
|
|
if (isDesktopPlatform ||
|
|
size.shortestSide < 600 ||
|
|
size.width >= navigationRailBreakpoint) {
|
|
return 1;
|
|
}
|
|
return size.shortestSide >= 800 ? 1.2 : 1.1;
|
|
}
|
|
|
|
EdgeInsets _scaledInsets(EdgeInsets value, double divisor) => EdgeInsets.only(
|
|
left: value.left / divisor,
|
|
top: value.top / divisor,
|
|
right: value.right / divisor,
|
|
bottom: value.bottom / divisor,
|
|
);
|
|
|
|
/// Scales the complete app surface on tablets, including controls, dialogs,
|
|
/// navigation, spacing and hit targets. The child receives the correspondingly
|
|
/// smaller logical viewport so responsive layouts still reflow instead of
|
|
/// being cropped, while [FittedBox] maps that viewport back to the full screen.
|
|
class AdaptiveUiScaler extends StatelessWidget {
|
|
const AdaptiveUiScaler({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final mediaQuery = MediaQuery.of(context);
|
|
final scale = adaptiveUiScaleForSize(mediaQuery.size);
|
|
if (scale == 1) return child;
|
|
|
|
final scaledSize = Size(
|
|
mediaQuery.size.width / scale,
|
|
mediaQuery.size.height / scale,
|
|
);
|
|
final scaledMediaQuery = mediaQuery.copyWith(
|
|
size: scaledSize,
|
|
// One inner logical pixel occupies [scale] outer logical pixels.
|
|
// Advertising the effective density keeps decoded artwork sharp.
|
|
devicePixelRatio: mediaQuery.devicePixelRatio * scale,
|
|
padding: _scaledInsets(mediaQuery.padding, scale),
|
|
viewPadding: _scaledInsets(mediaQuery.viewPadding, scale),
|
|
viewInsets: _scaledInsets(mediaQuery.viewInsets, scale),
|
|
systemGestureInsets: _scaledInsets(mediaQuery.systemGestureInsets, scale),
|
|
);
|
|
|
|
return SizedBox.expand(
|
|
child: FittedBox(
|
|
fit: BoxFit.fill,
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox.fromSize(
|
|
size: scaledSize,
|
|
child: MediaQuery(data: scaledMediaQuery, child: child),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Widest content span for a surface of [maxWidth]: lists, settings and
|
|
/// detail content stop at [contentMaxWidth], a comfortable reading width, and
|
|
/// center on wider tablet and landscape surfaces.
|
|
double adaptiveContentMaxWidth(
|
|
double maxWidth, {
|
|
double contentMaxWidth = defaultWideContentMaxWidth,
|
|
}) => maxWidth < contentMaxWidth ? maxWidth : contentMaxWidth;
|
|
|
|
/// Horizontal inset that centers content of [maxWidth] at
|
|
/// [adaptiveContentMaxWidth]; zero once it fits. Prefer this constraint-based
|
|
/// form when the widget may live inside an already clamped box (e.g. a bottom
|
|
/// sheet), where screen width would over-inset.
|
|
double wideInsetForWidth(
|
|
double maxWidth, {
|
|
double contentMaxWidth = defaultWideContentMaxWidth,
|
|
}) => maxWidth > contentMaxWidth ? (maxWidth - contentMaxWidth) / 2 : 0;
|
|
|
|
/// Horizontal inset that centers full-width list content on tablets/landscape;
|
|
/// zero on phones, so rows stop stretching across the whole screen. Desktop
|
|
/// pages run across the whole content pane, as Music's do, and center only
|
|
/// past [desktopContentMaxWidth].
|
|
double wideListInset(BuildContext context, {double? contentMaxWidth}) =>
|
|
wideInsetForWidth(
|
|
MediaQuery.sizeOf(context).width,
|
|
contentMaxWidth:
|
|
contentMaxWidth ??
|
|
(isDesktopPlatform
|
|
? desktopContentMaxWidth
|
|
: defaultWideContentMaxWidth),
|
|
);
|
|
|
|
const double desktopContentMaxWidth = 1600;
|
|
|
|
/// Discography cover geometry shared by loaded cards and loading placeholders.
|
|
double artistAlbumTileSize(BuildContext context) {
|
|
final scale = responsiveScale(context: context, min: 0.82, max: 1.05);
|
|
final textScale = effectiveTextScale(context);
|
|
return 140 * scale * (1 + (textScale - 1) * 0.12);
|
|
}
|
|
|
|
double artistAlbumSectionHeight(BuildContext context) =>
|
|
artistAlbumTileSize(context) +
|
|
64 +
|
|
((effectiveTextScale(context) - 1) * 14);
|
|
|
|
/// Scales fixed sizes with the shortest screen side, clamped to [min]..[max].
|
|
double responsiveScale({
|
|
required BuildContext context,
|
|
double min = 0.82,
|
|
double max = 1.08,
|
|
double baseShortestSide = 390,
|
|
}) {
|
|
final shortestSide = MediaQuery.sizeOf(context).shortestSide;
|
|
final scale = shortestSide / baseShortestSide;
|
|
if (scale < min) return min;
|
|
if (scale > max) return max;
|
|
return scale;
|
|
}
|
|
|
|
/// The system text scale clamped to 1.0..1.4 for fixed-height layouts.
|
|
double effectiveTextScale(BuildContext context) {
|
|
final textScale = MediaQuery.textScalerOf(context).scale(1.0);
|
|
if (textScale < 1.0) return 1.0;
|
|
if (textScale > 1.4) return 1.4;
|
|
return textScale;
|
|
}
|