Implement note deletion

It looks quite ugly, but it works.
This commit is contained in:
Vishesh Handa
2018-05-21 17:16:21 +02:00
parent 973f21a24c
commit 71d1aca6b5
4 changed files with 27 additions and 3 deletions

View File

@ -44,6 +44,7 @@ class JournalAppState extends State<JournalApp> {
home: new HomeScreen(
appState: appState,
noteAdder: addNote,
noteRemover: removeNote,
),
theme: new ThemeData(
brightness: Brightness.dark,

View File

@ -37,7 +37,8 @@ class FileStorage {
Future<Directory> saveNotes(List<Note> notes) async {
final dir = await getDirectory();
//await dir.delete(recursive: true);
await dir.delete(recursive: true);
await dir.create();
for (var note in notes) {
var filePath = p.join(dir.path, note.id);

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'note.dart';
@ -7,11 +8,16 @@ typedef void NoteSelectedFunction(Note note);
class JournalList extends StatelessWidget {
final NoteSelectedFunction noteSelectedFunction;
final NoteRemover noteRemover;
final List<Note> notes;
final _biggerFont = const TextStyle(fontSize: 18.0);
JournalList({this.noteSelectedFunction, this.notes});
JournalList({
@required this.notes,
@required this.noteSelectedFunction,
@required this.noteRemover,
});
@override
Widget build(BuildContext context) {
@ -22,7 +28,20 @@ class JournalList extends StatelessWidget {
return null;
}
//if (i.isOdd) return new Divider();
return _buildRow(context, notes[i]);
var note = notes[i];
return new Dismissible(
key: new Key(note.id),
child: _buildRow(context, note),
background: new Container(color: Colors.red),
onDismissed: (direction) {
noteRemover(note);
Scaffold
.of(context)
.showSnackBar(new SnackBar(content: new Text("Note deleted")));
},
);
},
);
}

View File

@ -9,10 +9,12 @@ import 'package:journal/note_viewer.dart';
class HomeScreen extends StatelessWidget {
final AppState appState;
final NoteAdder noteAdder;
final NoteRemover noteRemover;
HomeScreen({
@required this.appState,
@required this.noteAdder,
@required this.noteRemover,
});
@override
@ -47,6 +49,7 @@ class HomeScreen extends StatelessWidget {
body: new JournalList(
notes: appState.notes,
noteSelectedFunction: (note) => _noteSelected(note, context),
noteRemover: noteRemover,
),
);
}