mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 04:07:53 +08:00
Give each Note a unique id
Otherwise we're overwriting that one note.
This commit is contained in:
10
lib/app.dart
10
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<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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -41,7 +41,6 @@ class NoteEditor extends StatelessWidget {
|
||||
onPressed: () {
|
||||
var body = noteTextKey.currentState.value;
|
||||
var note = new Note(
|
||||
id: "1",
|
||||
createdAt: _createdAt,
|
||||
body: body,
|
||||
);
|
||||
|
@ -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:
|
||||
|
@ -8,6 +8,7 @@ dependencies:
|
||||
intl: "^0.15.6"
|
||||
path: "^1.5.1"
|
||||
path_provider: "^0.4.0"
|
||||
uuid: "^1.0.0"
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
Reference in New Issue
Block a user