Give each Note a unique id

Otherwise we're overwriting that one note.
This commit is contained in:
Vishesh Handa
2018-05-21 17:04:03 +02:00
parent 0cb36b2981
commit 973f21a24c
5 changed files with 14 additions and 9 deletions

View File

@ -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<JournalApp> {
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);
});
}

View File

@ -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<String, dynamic> json) {
return new Note(

View File

@ -41,7 +41,6 @@ class NoteEditor extends StatelessWidget {
onPressed: () {
var body = noteTextKey.currentState.value;
var note = new Note(
id: "1",
createdAt: _createdAt,
body: body,
);

View File

@ -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:

View File

@ -8,6 +8,7 @@ dependencies:
intl: "^0.15.6"
path: "^1.5.1"
path_provider: "^0.4.0"
uuid: "^1.0.0"
dev_dependencies: