86 lines
2.3 KiB
Dart
86 lines
2.3 KiB
Dart
class Todo {
|
|
final String id;
|
|
final String title;
|
|
final String? description;
|
|
final bool isCompleted;
|
|
final String priority;
|
|
final DateTime? dueDate;
|
|
final int sortOrder;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
|
|
const Todo({
|
|
required this.id,
|
|
required this.title,
|
|
this.description,
|
|
this.isCompleted = false,
|
|
this.priority = 'medium',
|
|
this.dueDate,
|
|
this.sortOrder = 0,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
Todo copyWith({
|
|
String? id,
|
|
String? title,
|
|
String? description,
|
|
bool? isCompleted,
|
|
String? priority,
|
|
DateTime? dueDate,
|
|
int? sortOrder,
|
|
DateTime? createdAt,
|
|
DateTime? updatedAt,
|
|
}) {
|
|
return Todo(
|
|
id: id ?? this.id,
|
|
title: title ?? this.title,
|
|
description: description ?? this.description,
|
|
isCompleted: isCompleted ?? this.isCompleted,
|
|
priority: priority ?? this.priority,
|
|
dueDate: dueDate ?? this.dueDate,
|
|
sortOrder: sortOrder ?? this.sortOrder,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'isCompleted': isCompleted,
|
|
'priority': priority,
|
|
'dueDate': dueDate?.toIso8601String(),
|
|
'sortOrder': sortOrder,
|
|
'createdAt': createdAt?.toIso8601String(),
|
|
'updatedAt': updatedAt?.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory Todo.fromJson(Map<String, dynamic> json) {
|
|
return Todo(
|
|
id: json['id'] as String,
|
|
title: json['title'] as String,
|
|
description: json['description'] as String?,
|
|
isCompleted: json['isCompleted'] as bool? ?? false,
|
|
priority: json['priority'] as String? ?? 'medium',
|
|
dueDate: json['dueDate'] != null ? DateTime.parse(json['dueDate'] as String) : null,
|
|
sortOrder: json['sortOrder'] as int? ?? 0,
|
|
createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt'] as String) : null,
|
|
updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt'] as String) : null,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Todo && id == other.id;
|
|
|
|
@override
|
|
int get hashCode => id.hashCode;
|
|
|
|
@override
|
|
String toString() => 'Todo(id: $id, title: $title, isCompleted: $isCompleted)';
|
|
}
|