67 lines
1.5 KiB
Dart
67 lines
1.5 KiB
Dart
import 'tag.dart';
|
|
|
|
class Todo {
|
|
final int? id;
|
|
String title;
|
|
String description;
|
|
bool isCompleted;
|
|
DateTime createdAt;
|
|
DateTime? completedAt;
|
|
List<Tag> tags;
|
|
|
|
Todo({
|
|
this.id,
|
|
required this.title,
|
|
required this.description,
|
|
this.isCompleted = false,
|
|
required this.createdAt,
|
|
this.completedAt,
|
|
this.tags = const [],
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'isCompleted': isCompleted ? 1 : 0,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'completedAt': completedAt?.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
static Todo fromMap(Map<String, dynamic> map) {
|
|
return Todo(
|
|
id: map['id'],
|
|
title: map['title'],
|
|
description: map['description'],
|
|
isCompleted: map['isCompleted'] == 1,
|
|
createdAt: DateTime.parse(map['createdAt']),
|
|
completedAt: map['completedAt'] != null
|
|
? DateTime.parse(map['completedAt'])
|
|
: null,
|
|
tags: [],
|
|
);
|
|
}
|
|
|
|
Todo copyWith({
|
|
int? id,
|
|
String? title,
|
|
String? description,
|
|
bool? isCompleted,
|
|
DateTime? createdAt,
|
|
DateTime? completedAt,
|
|
List<Tag>? tags,
|
|
}) {
|
|
return Todo(
|
|
id: id ?? this.id,
|
|
title: title ?? this.title,
|
|
description: description ?? this.description,
|
|
isCompleted: isCompleted ?? this.isCompleted,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
completedAt: completedAt ?? this.completedAt,
|
|
tags: tags ?? this.tags,
|
|
);
|
|
}
|
|
}
|