mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Implement note deletion
It looks quite ugly, but it works.
This commit is contained in:
@ -44,6 +44,7 @@ class JournalAppState extends State<JournalApp> {
|
||||
home: new HomeScreen(
|
||||
appState: appState,
|
||||
noteAdder: addNote,
|
||||
noteRemover: removeNote,
|
||||
),
|
||||
theme: new ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
|
@ -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);
|
||||
|
@ -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")));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user