mirror of
https://github.com/cyberbread-ru/notepad.git
synced 2026-07-14 12:51:01 +03:00
67 lines
1.7 KiB
Dart
67 lines
1.7 KiB
Dart
class Note {
|
|
final String id;
|
|
final String title;
|
|
final String content;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
|
|
const Note({
|
|
required this.id,
|
|
required this.title,
|
|
required this.content,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
Note copyWith({
|
|
String? title,
|
|
String? content,
|
|
DateTime? updatedAt,
|
|
}) {
|
|
return Note(
|
|
id: id,
|
|
title: title ?? this.title,
|
|
content: content ?? this.content,
|
|
createdAt: createdAt,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'title': title,
|
|
'content': content,
|
|
'created_at': createdAt.toIso8601String(),
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
};
|
|
|
|
factory Note.fromJson(Map<String, dynamic> json) => Note(
|
|
id: json['id'] as String,
|
|
title: json['title'] as String,
|
|
content: json['content'] as String,
|
|
createdAt: DateTime.parse(json['created_at'] as String),
|
|
updatedAt: DateTime.parse(json['updated_at'] as String),
|
|
);
|
|
|
|
// SQLite row → Note
|
|
factory Note.fromMap(Map<String, dynamic> map) => Note(
|
|
id: map['id'] as String,
|
|
title: map['title'] as String,
|
|
content: map['content'] as String,
|
|
createdAt: DateTime.parse(map['created_at'] as String),
|
|
updatedAt: DateTime.parse(map['updated_at'] as String),
|
|
);
|
|
|
|
// Note → SQLite row
|
|
Map<String, dynamic> toMap() => {
|
|
'id': id,
|
|
'title': title,
|
|
'content': content,
|
|
'created_at': createdAt.toIso8601String(),
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
};
|
|
|
|
@override
|
|
String toString() => 'Note(id: $id, title: $title)';
|
|
}
|