From 23d151e4e6d728e2ecf622d20724c113b6190cfe Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Sun, 22 Nov 2026 22:05:55 +0700 Subject: [PATCH] fix(metadata): keep the row's picture on a landed cover until its own is decoded The cover that flies from a list row into track details lands on the header's cover, which is decoded at the full width of the screen. The flight shows the row's picture under it, so a decode still running is not seen while the cover flies. That only held while the flight outlasted the decode: the Material page push went from 800 ms to 350 ms, and a large picture in a file is not decoded by then. The cover landed, went empty and popped in when its decode finished, the first time a song was opened. With a 7000 px PNG on the emulator the cover was gone for 0.8 s. The header's cover now shows the row's picture itself for as long as it has no frame of its own, so the picture that flew in stays where it landed and the sharp one takes over when it is there. It is the picture of the row this song was opened from: moving to another song inside the page does not show it. --- lib/screens/track_metadata_header.dart | 22 +++++- lib/screens/track_metadata_screen.dart | 7 ++ test/track_metadata_file_access_test.dart | 81 +++++++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/lib/screens/track_metadata_header.dart b/lib/screens/track_metadata_header.dart index 74240542d..3f478d1c5 100644 --- a/lib/screens/track_metadata_header.dart +++ b/lib/screens/track_metadata_header.dart @@ -40,6 +40,11 @@ extension _TrackMetadataHeader on _TrackMetadataScreenState { begin: flight.tokens.borderRadiusThumb, end: headerCorners?.resolve(Directionality.of(flight)), ).animate(animation); + if (direction == HeroFlightDirection.push) { + // Kept for the landing: the flight can end before the decode does. + _flownCover = (from.widget as Hero).child; + _flownCoverItem = _itemId; + } return AnimatedBuilder( animation: corners, builder: (context, cover) => ClipRRect( @@ -93,10 +98,13 @@ extension _TrackMetadataHeader on _TrackMetadataScreenState { ), ); + // [landing] is the cover a list row's picture flies into: until its own + // picture is decoded it shows the row's, read when it is built. Widget artworkImage({ required int cacheWidth, int? cacheHeight, required double iconSize, + bool landing = false, }) { final source = artworkSource; if (source == null) return placeholder(iconSize); @@ -106,7 +114,9 @@ extension _TrackMetadataHeader on _TrackMetadataScreenState { fit: BoxFit.cover, memCacheWidth: cacheWidth, memCacheHeight: cacheHeight, - placeholder: (_, _) => ColoredBox(color: colorScheme.surface), + placeholder: (_, _) => + (landing ? _landedCover : null) ?? + ColoredBox(color: colorScheme.surface), errorWidget: (_, _, _) => placeholder(iconSize), ); } @@ -119,6 +129,10 @@ extension _TrackMetadataHeader on _TrackMetadataScreenState { cacheHeight: cacheHeight, gaplessPlayback: true, filterQuality: FilterQuality.low, + frameBuilder: landing + ? (_, picture, frame, _) => + frame == null ? _landedCover ?? picture : picture + : null, errorBuilder: (_, _, _) => placeholder(iconSize), ); } @@ -154,7 +168,11 @@ extension _TrackMetadataHeader on _TrackMetadataScreenState { flightShuttleBuilder: _coverFlight, child: SizedBox.square( dimension: coverSize, - child: artworkImage(cacheWidth: coverCacheWidth, iconSize: 48), + child: artworkImage( + cacheWidth: coverCacheWidth, + iconSize: 48, + landing: true, + ), ), ), // Built inside the header, so it reads the header's artwork scheme. diff --git a/lib/screens/track_metadata_screen.dart b/lib/screens/track_metadata_screen.dart index 486e20625..7f475cdcb 100644 --- a/lib/screens/track_metadata_screen.dart +++ b/lib/screens/track_metadata_screen.dart @@ -270,6 +270,13 @@ class _TrackMetadataScreenState extends ConsumerState static final RegExp _leadingOrTrailingDots = RegExp(r'^\.+|\.+$'); String get _coverCacheKey => _itemId; + /// The picture of the list row the cover flew in from, and its song. + Widget? _flownCover; + String? _flownCoverItem; + + /// What the header's cover shows until its own picture is decoded. + Widget? get _landedCover => _flownCoverItem == _itemId ? _flownCover : null; + /// Shared by the lyrics box and its scrollbar. final _lyricsScrollController = ScrollController(); diff --git a/test/track_metadata_file_access_test.dart b/test/track_metadata_file_access_test.dart index 53f26c63a..8bb810091 100644 --- a/test/track_metadata_file_access_test.dart +++ b/test/track_metadata_file_access_test.dart @@ -9,6 +9,7 @@ import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/providers/download_history_provider.dart'; import 'package:mornye/providers/music_player_provider.dart'; import 'package:mornye/screens/track_metadata_screen.dart'; +import 'package:mornye/services/library_database.dart'; import 'package:mornye/services/source_deletion_events.dart'; import 'package:mornye/services/source_metadata_events.dart'; import 'package:mornye/theme/mornye_theme.dart'; @@ -276,5 +277,85 @@ void main() { expect(find.byKey(rowCover), findsNothing); expect(tester.takeException(), isNull); }); + + testWidgets('the row picture stays on a cover that is not decoded when ' + 'the flight lands (Mornye=$mornye)', (tester) async { + SharedPreferences.setMockInitialValues({}); + final messenger = tester.binding.defaultBinaryMessenger; + messenger.setMockMethodCallHandler( + channel, + (call) async => call.method == 'safStat' ? {'exists': false} : null, + ); + addTearDown(() => messenger.setMockMethodCallHandler(channel, null)); + const row = Key('row'); + const rowCover = Key('row-cover'); + // Never decoded here: a test reads no file outside runAsync. + final item = LocalLibraryItem( + id: 'landing-track', + trackName: 'Track', + artistName: 'Artist', + albumName: 'Album', + filePath: 'content://provider/music/landing.flac', + coverPath: '${cache.path}/landing-cover.png', + scannedAt: DateTime(2026), + ); + await tester.pumpWidget( + ProviderScope( + child: MaterialApp( + theme: mornye + ? MornyeTheme.build(Brightness.dark) + : ThemeData.dark(useMaterial3: true), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Builder( + builder: (context) => Scaffold( + body: Center( + child: GestureDetector( + key: row, + onTap: () => Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => TrackMetadataScreen( + localItem: item, + coverHeroTag: 'row', + ), + ), + ), + child: const SizedBox.square( + dimension: 56, + child: Hero( + tag: 'row', + child: ColoredBox( + key: rowCover, + color: Color(0xFF336699), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + Finder inRow() => + find.descendant(of: find.byKey(row), matching: find.byKey(rowCover)); + Finder onPage() => find.descendant( + of: find.byType(TrackMetadataScreen), + matching: find.byKey(rowCover), + ); + + await tester.tap(find.byKey(row)); + await tester.pumpAndSettle(); + // Landed with no picture of its own yet, the cover keeps the row's + // instead of going empty. + expect(onPage(), findsOneWidget); + expect(tester.getSize(onPage()).width, greaterThan(56)); + + Navigator.of(tester.element(find.byType(TrackMetadataScreen))).pop(); + await tester.pumpAndSettle(); + expect(inRow(), findsOneWidget); + expect(find.byKey(rowCover), findsOneWidget); + expect(tester.takeException(), isNull); + }); } }