From e30e7a5c24f152375af9af4351c330b540b9aad4 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 6 Sep 2024 12:52:57 +0800 Subject: [PATCH] :bug: Fix source track details --- lib/screens/player/source_details.dart | 23 ++++++++++++++++---- lib/screens/player/view.dart | 6 +++-- lib/widgets/player/track_source_details.dart | 10 +++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/screens/player/source_details.dart b/lib/screens/player/source_details.dart index 8ea9bae..cf10f1c 100644 --- a/lib/screens/player/source_details.dart +++ b/lib/screens/player/source_details.dart @@ -1,15 +1,19 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:rhythm_box/services/server/active_sourced_track.dart'; +import 'package:rhythm_box/services/sourced_track/sourced_track.dart'; import 'package:rhythm_box/widgets/player/track_source_details.dart'; class SourceDetailsPopup extends StatelessWidget { const SourceDetailsPopup({super.key}); + Future _pullActiveTrack() async { + final ActiveSourcedTrackProvider activeSourcedTrack = Get.find(); + return activeSourcedTrack.state.value; + } + @override Widget build(BuildContext context) { - final ActiveSourcedTrackProvider activeTrack = Get.find(); - return SizedBox( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -20,8 +24,19 @@ class SourceDetailsPopup extends StatelessWidget { ).paddingOnly(left: 24, right: 24, top: 32, bottom: 16), Expanded( child: Obx( - () => TrackSourceDetails( - track: activeTrack.state.value!, + () => FutureBuilder( + future: _pullActiveTrack(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return TrackSourceDetails( + track: snapshot.data!, + ); + } + + return const Center( + child: CircularProgressIndicator(), + ); + }, ).paddingSymmetric(horizontal: 24), ), ) diff --git a/lib/screens/player/view.dart b/lib/screens/player/view.dart index a6516fd..2595299 100644 --- a/lib/screens/player/view.dart +++ b/lib/screens/player/view.dart @@ -311,8 +311,10 @@ class _PlayerScreenState extends State { const Gap(20), SizedBox( height: 40, - child: ListView( - scrollDirection: Axis.horizontal, + child: Wrap( + alignment: WrapAlignment.center, + spacing: 4, + runSpacing: 4, children: [ TextButton.icon( icon: const Icon(Icons.queue_music), diff --git a/lib/widgets/player/track_source_details.dart b/lib/widgets/player/track_source_details.dart index b7901fc..f0d71bd 100644 --- a/lib/widgets/player/track_source_details.dart +++ b/lib/widgets/player/track_source_details.dart @@ -4,10 +4,9 @@ import 'package:rhythm_box/services/sourced_track/sourced_track.dart'; import 'package:rhythm_box/services/sourced_track/sources/netease.dart'; import 'package:rhythm_box/services/sourced_track/sources/piped.dart'; import 'package:rhythm_box/services/sourced_track/sources/youtube.dart'; -import 'package:spotify/spotify.dart'; class TrackSourceDetails extends StatelessWidget { - final Track track; + final SourcedTrack track; const TrackSourceDetails({super.key, required this.track}); @@ -25,14 +24,11 @@ class TrackSourceDetails extends StatelessWidget { 'Title': track.name!, 'Artist': track.artists?.map((x) => x.name).join(', '), 'Album': track.album!.name!, - 'Duration': (track is SourcedTrack - ? (track as SourcedTrack).sourceInfo.duration - : track.duration!) - .toHumanReadableString(), + 'Duration': track.sourceInfo.duration.toHumanReadableString(), if (track.album!.releaseDate != null) 'Released': track.album!.releaseDate, 'Popularity': track.popularity?.toString() ?? '0', - 'Provider': sourceInfoToLabelMap[track.runtimeType], + 'Provider': sourceInfoToLabelMap[track.sourceInfo.runtimeType], }; return Table(