instruction_app/lib/models/instruction.dart

50 lines
1.1 KiB
Dart

class Instruction {
final String? id;
final String title;
final String content;
final List<String> tags;
final DateTime createdAt;
Instruction({
this.id,
required this.title,
required this.content,
required this.tags,
required this.createdAt,
});
Instruction copyWith({
String? id,
String? title,
String? content,
List<String>? tags,
DateTime? createdAt,
}) {
return Instruction(
id: id ?? this.id,
title: title ?? this.title,
content: content ?? this.content,
tags: tags ?? this.tags,
createdAt: createdAt ?? this.createdAt,
);
}
factory Instruction.fromJson(Map<String, dynamic> json) {
return Instruction(
id: json['id'],
title: json['title'],
content: json['content'],
tags: List<String>.from(json['tags'] ?? []),
createdAt: DateTime.parse(json['createdAt']),
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'title': title,
'content': content,
'tags': tags,
'createdAt': createdAt.toIso8601String(),
};
}
}