Files
YungR1otz/lib/features/music/domain/models/track_model.dart
Lucas Saburido cabf2025cd first commit
2026-05-13 16:26:45 +01:00

55 lines
1.4 KiB
Dart

class TrackModel {
const TrackModel({
required this.id,
required this.userId,
required this.title,
required this.audioUrl,
required this.genreTag,
required this.plays,
required this.createdAt,
required this.username,
this.featured = false,
});
final String id;
final String userId;
final String title;
final String audioUrl;
final String genreTag;
final int plays;
final DateTime createdAt;
final String username;
final bool featured;
factory TrackModel.fromJson(Map<String, dynamic> json, {String? username}) {
return TrackModel(
id: json['id'] as String,
userId: json['user_id'] as String,
title: (json['title'] as String?) ?? 'UNTITLED',
audioUrl: (json['audio_url'] as String?) ?? '',
genreTag: (json['genre_tag'] as String?) ?? 'UNKNOWN',
plays: (json['plays'] as int?) ?? 0,
createdAt: DateTime.parse(json['created_at'] as String),
username: username ?? 'RIOTER',
featured: (json['featured'] as bool?) ?? false,
);
}
TrackModel copyWith({
int? plays,
bool? featured,
}) {
return TrackModel(
id: id,
userId: userId,
title: title,
audioUrl: audioUrl,
genreTag: genreTag,
plays: plays ?? this.plays,
createdAt: createdAt,
username: username,
featured: featured ?? this.featured,
);
}
}