RhythmBox/lib/widgets/player/track_source_details.dart

71 lines
2.2 KiB
Dart
Raw Normal View History

2024-09-04 16:01:58 +00:00
import 'package:flutter/material.dart';
import 'package:rhythm_box/services/duration.dart';
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';
class TrackSourceDetails extends StatelessWidget {
2024-09-06 04:52:57 +00:00
final SourcedTrack track;
2024-09-04 16:01:58 +00:00
const TrackSourceDetails({super.key, required this.track});
static final sourceInfoToLabelMap = {
YoutubeSourceInfo: 'YouTube',
PipedSourceInfo: 'Piped',
NeteaseSourceInfo: 'Netease',
};
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final detailsMap = {
'Title': track.name!,
'Artist': track.artists?.map((x) => x.name).join(', '),
'Album': track.album!.name!,
2024-09-06 04:52:57 +00:00
'Duration': track.sourceInfo.duration.toHumanReadableString(),
2024-09-04 16:01:58 +00:00
if (track.album!.releaseDate != null)
'Released': track.album!.releaseDate,
'Popularity': track.popularity?.toString() ?? '0',
2024-09-06 04:52:57 +00:00
'Provider': sourceInfoToLabelMap[track.sourceInfo.runtimeType],
2024-09-04 16:01:58 +00:00
};
return Table(
columnWidths: const {
0: FixedColumnWidth(95),
1: FixedColumnWidth(10),
2: FlexColumnWidth(1),
},
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
for (final entry in detailsMap.entries)
TableRow(
children: [
TableCell(
verticalAlignment: TableCellVerticalAlignment.top,
child: Text(
entry.key,
style: theme.textTheme.titleMedium,
),
),
const TableCell(
verticalAlignment: TableCellVerticalAlignment.top,
child: Text(':'),
),
if (entry.value is Widget)
entry.value as Widget
else if (entry.value is String)
Text(
entry.value as String,
style: theme.textTheme.bodyMedium,
)
else
const Text('Unknown'),
],
),
],
);
}
}