diff --git a/lib/app.dart b/lib/app.dart index a82c31e5..f479c744 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,5 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:uuid/uuid.dart'; + import 'package:journal/file_storage.dart'; import 'package:journal/note.dart'; import 'package:journal/screens/home_screen.dart'; @@ -61,12 +63,8 @@ class JournalAppState extends State { void addNote(Note note) { print("Adding a note " + note.toString()); setState(() { - try { - appState.notes.add(note); - } catch (err) { - print("WTF"); - print(err); - } + note.id = new Uuid().v4(); + appState.notes.insert(0, note); }); } diff --git a/lib/note.dart b/lib/note.dart index a6922bd9..4977099b 100644 --- a/lib/note.dart +++ b/lib/note.dart @@ -3,11 +3,11 @@ typedef NoteRemover(Note note); typedef NoteUpdator(Note note); class Note implements Comparable { - final String id; + String id; final DateTime createdAt; final String body; - const Note({this.createdAt, this.body, this.id}); + Note({this.createdAt, this.body, this.id}); factory Note.fromJson(Map json) { return new Note( diff --git a/lib/note_editor.dart b/lib/note_editor.dart index 2a73f745..f6faf41d 100644 --- a/lib/note_editor.dart +++ b/lib/note_editor.dart @@ -41,7 +41,6 @@ class NoteEditor extends StatelessWidget { onPressed: () { var body = noteTextKey.currentState.value; var note = new Note( - id: "1", createdAt: _createdAt, body: body, ); diff --git a/pubspec.lock b/pubspec.lock index f537d2f0..1c06f88d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -366,6 +366,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.0+4" + uuid: + dependency: "direct main" + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e240a01e..de210180 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,6 +8,7 @@ dependencies: intl: "^0.15.6" path: "^1.5.1" path_provider: "^0.4.0" + uuid: "^1.0.0" dev_dependencies: