93 lines
2.1 KiB
Dart
93 lines
2.1 KiB
Dart
// Author: fengshengxiong
|
|
// Date: 2024/6/24
|
|
// Description: 播放列表模型
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:hive/hive.dart';
|
|
import 'package:tone_snap/data/models/music_model.dart';
|
|
|
|
part 'playlist_model.g.dart';
|
|
|
|
@HiveType(typeId: 3)
|
|
class PlaylistModel extends HiveObject {
|
|
@HiveField(0)
|
|
String id;
|
|
@HiveField(1)
|
|
String title;
|
|
|
|
/// playlists
|
|
@HiveField(2)
|
|
int? milliseconds;
|
|
@HiveField(3)
|
|
List<MusicModel>? musicList;
|
|
|
|
/// collect_playlists
|
|
@HiveField(4)
|
|
String? params;
|
|
@HiveField(5)
|
|
String? coverUrl;
|
|
@HiveField(6)
|
|
String? subtitle;
|
|
@HiveField(7)
|
|
String? musicType;
|
|
|
|
PlaylistModel({
|
|
required this.id,
|
|
required this.title,
|
|
this.milliseconds,
|
|
this.musicList,
|
|
this.params,
|
|
this.coverUrl,
|
|
this.subtitle,
|
|
this.musicType,
|
|
});
|
|
|
|
PlaylistModel copyWith({
|
|
required String id,
|
|
required String title,
|
|
int? milliseconds,
|
|
List<MusicModel>? musicList,
|
|
String? params,
|
|
String? coverUrl,
|
|
String? subtitle,
|
|
String? musicType,
|
|
}) =>
|
|
PlaylistModel(
|
|
id: id,
|
|
title: title,
|
|
milliseconds: milliseconds ?? this.milliseconds,
|
|
musicList: musicList ?? this.musicList,
|
|
params: params ?? this.params,
|
|
coverUrl: coverUrl ?? this.coverUrl,
|
|
subtitle: subtitle ?? this.subtitle,
|
|
musicType: musicType ?? this.musicType,
|
|
);
|
|
|
|
factory PlaylistModel.fromJson(String str) => PlaylistModel.fromMap(json.decode(str));
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory PlaylistModel.fromMap(Map<String, dynamic> json) => PlaylistModel(
|
|
id: json["id"],
|
|
title: json["title"],
|
|
milliseconds: json["milliseconds"],
|
|
musicList: json["musicList"],
|
|
params: json["params"],
|
|
coverUrl: json["coverUrl"],
|
|
subtitle: json["subtitle"],
|
|
musicType: json["musicType"],
|
|
);
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
"id": id,
|
|
"title": title,
|
|
"milliseconds": milliseconds,
|
|
"musicList": musicList,
|
|
"params": params,
|
|
"coverUrl": coverUrl,
|
|
"subtitle": subtitle,
|
|
"musicType": musicType,
|
|
};
|
|
}
|