feat: add totalTracks to Track model and refine EP/single classification (#202)

This commit is contained in:
zarzet
2026-03-11 01:10:50 +07:00
parent f2ae1398db
commit 8d45e023b2
6 changed files with 41 additions and 10 deletions
+13 -1
View File
@@ -21,6 +21,7 @@ class Track {
final ServiceAvailability? availability;
final String? source;
final String? albumType;
final int? totalTracks;
final String? itemType;
const Track({
@@ -41,10 +42,21 @@ class Track {
this.availability,
this.source,
this.albumType,
this.totalTracks,
this.itemType,
});
bool get isSingle => albumType == 'single' || albumType == 'ep';
bool get isSingle {
switch (albumType?.toLowerCase()) {
case 'single':
return true;
case 'ep':
final count = totalTracks;
return count == null || count <= 1;
default:
return false;
}
}
bool get isAlbumItem => itemType == 'album';
+2
View File
@@ -28,6 +28,7 @@ Track _$TrackFromJson(Map<String, dynamic> json) => Track(
),
source: json['source'] as String?,
albumType: json['albumType'] as String?,
totalTracks: (json['totalTracks'] as num?)?.toInt(),
itemType: json['itemType'] as String?,
);
@@ -49,6 +50,7 @@ Map<String, dynamic> _$TrackToJson(Track instance) => <String, dynamic>{
'availability': instance.availability,
'source': instance.source,
'albumType': instance.albumType,
'totalTracks': instance.totalTracks,
'itemType': instance.itemType,
};