mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Note: Rename 'createdAt' to 'created'
My notes already use the key 'created', and I don't want to have to change that.
This commit is contained in:
@ -4,10 +4,10 @@ typedef NoteUpdator(Note note);
|
|||||||
|
|
||||||
class Note implements Comparable {
|
class Note implements Comparable {
|
||||||
String id;
|
String id;
|
||||||
DateTime createdAt;
|
DateTime created;
|
||||||
String body;
|
String body;
|
||||||
|
|
||||||
Note({this.createdAt, this.body, this.id});
|
Note({this.created, this.body, this.id});
|
||||||
|
|
||||||
factory Note.fromJson(Map<String, dynamic> json) {
|
factory Note.fromJson(Map<String, dynamic> json) {
|
||||||
String id;
|
String id;
|
||||||
@ -22,21 +22,21 @@ class Note implements Comparable {
|
|||||||
|
|
||||||
return new Note(
|
return new Note(
|
||||||
id: id,
|
id: id,
|
||||||
createdAt: DateTime.parse(json['createdAt']),
|
created: DateTime.parse(json['created']),
|
||||||
body: json['body'],
|
body: json['body'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
"createdAt": createdAt.toIso8601String(),
|
"created": created.toIso8601String(),
|
||||||
"body": body,
|
"body": body,
|
||||||
"id": id,
|
"id": id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => id.hashCode ^ createdAt.hashCode ^ body.hashCode;
|
int get hashCode => id.hashCode ^ created.hashCode ^ body.hashCode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
@ -45,15 +45,15 @@ class Note implements Comparable {
|
|||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
id == other.id &&
|
id == other.id &&
|
||||||
body == other.body &&
|
body == other.body &&
|
||||||
createdAt == other.createdAt;
|
created == other.created;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Note{id: $id, body: $body, createdAt: $createdAt}';
|
return 'Note{id: $id, body: $body, createdAt: $created}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int compareTo(other) => createdAt.compareTo(other.createdAt);
|
int compareTo(other) => created.compareTo(other.created);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppState {
|
class AppState {
|
||||||
|
@ -80,7 +80,7 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
var noteContent = noteTextKey.currentState.value;
|
var noteContent = noteTextKey.currentState.value;
|
||||||
var note = new Note(
|
var note = new Note(
|
||||||
createdAt: _createdAt,
|
created: _createdAt,
|
||||||
body: noteContent,
|
body: noteContent,
|
||||||
);
|
);
|
||||||
container.addNote(note);
|
container.addNote(note);
|
||||||
|
@ -85,11 +85,11 @@ class NoteViewer extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildHeader(BuildContext context) {
|
Widget _buildHeader(BuildContext context) {
|
||||||
var dateStr = DateFormat('MMM dd, yyyy').format(note.createdAt);
|
var dateStr = DateFormat('MMM dd, yyyy').format(note.created);
|
||||||
var timeStr = DateFormat('EEEE H:m').format(note.createdAt);
|
var timeStr = DateFormat('EEEE H:m').format(note.created);
|
||||||
|
|
||||||
var bigNum = new Text(
|
var bigNum = new Text(
|
||||||
note.createdAt.day.toString(),
|
note.created.day.toString(),
|
||||||
style: TextStyle(fontSize: 40.0),
|
style: TextStyle(fontSize: 40.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ class JournalList extends StatelessWidget {
|
|||||||
|
|
||||||
Widget _buildRow(BuildContext context, Note journal, int noteIndex) {
|
Widget _buildRow(BuildContext context, Note journal, int noteIndex) {
|
||||||
var formatter = new DateFormat('dd MMM, yyyy');
|
var formatter = new DateFormat('dd MMM, yyyy');
|
||||||
var title = formatter.format(journal.createdAt);
|
var title = formatter.format(journal.created);
|
||||||
|
|
||||||
var timeFormatter = new DateFormat('Hm');
|
var timeFormatter = new DateFormat('Hm');
|
||||||
var time = timeFormatter.format(journal.createdAt);
|
var time = timeFormatter.format(journal.created);
|
||||||
|
|
||||||
var body = journal.body;
|
var body = journal.body;
|
||||||
body = body.replaceAll("\n", " ");
|
body = body.replaceAll("\n", " ");
|
||||||
|
@ -8,7 +8,7 @@ import 'package:test/test.dart';
|
|||||||
main() {
|
main() {
|
||||||
group('Serializers', () {
|
group('Serializers', () {
|
||||||
var note =
|
var note =
|
||||||
Note(id: "2", body: "This is the body", createdAt: new DateTime.now());
|
Note(id: "2", body: "This is the body", created: new DateTime.now());
|
||||||
|
|
||||||
test('JSON Serializer', () {
|
test('JSON Serializer', () {
|
||||||
var jsonSerializer = new JsonNoteSerializer();
|
var jsonSerializer = new JsonNoteSerializer();
|
||||||
|
Reference in New Issue
Block a user