mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +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(
|
home: new HomeScreen(
|
||||||
appState: appState,
|
appState: appState,
|
||||||
noteAdder: addNote,
|
noteAdder: addNote,
|
||||||
|
noteRemover: removeNote,
|
||||||
),
|
),
|
||||||
theme: new ThemeData(
|
theme: new ThemeData(
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
|
@ -37,7 +37,8 @@ class FileStorage {
|
|||||||
|
|
||||||
Future<Directory> saveNotes(List<Note> notes) async {
|
Future<Directory> saveNotes(List<Note> notes) async {
|
||||||
final dir = await getDirectory();
|
final dir = await getDirectory();
|
||||||
//await dir.delete(recursive: true);
|
await dir.delete(recursive: true);
|
||||||
|
await dir.create();
|
||||||
|
|
||||||
for (var note in notes) {
|
for (var note in notes) {
|
||||||
var filePath = p.join(dir.path, note.id);
|
var filePath = p.join(dir.path, note.id);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import 'note.dart';
|
import 'note.dart';
|
||||||
@ -7,11 +8,16 @@ typedef void NoteSelectedFunction(Note note);
|
|||||||
|
|
||||||
class JournalList extends StatelessWidget {
|
class JournalList extends StatelessWidget {
|
||||||
final NoteSelectedFunction noteSelectedFunction;
|
final NoteSelectedFunction noteSelectedFunction;
|
||||||
|
final NoteRemover noteRemover;
|
||||||
final List<Note> notes;
|
final List<Note> notes;
|
||||||
|
|
||||||
final _biggerFont = const TextStyle(fontSize: 18.0);
|
final _biggerFont = const TextStyle(fontSize: 18.0);
|
||||||
|
|
||||||
JournalList({this.noteSelectedFunction, this.notes});
|
JournalList({
|
||||||
|
@required this.notes,
|
||||||
|
@required this.noteSelectedFunction,
|
||||||
|
@required this.noteRemover,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -22,7 +28,20 @@ class JournalList extends StatelessWidget {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//if (i.isOdd) return new Divider();
|
//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 {
|
class HomeScreen extends StatelessWidget {
|
||||||
final AppState appState;
|
final AppState appState;
|
||||||
final NoteAdder noteAdder;
|
final NoteAdder noteAdder;
|
||||||
|
final NoteRemover noteRemover;
|
||||||
|
|
||||||
HomeScreen({
|
HomeScreen({
|
||||||
@required this.appState,
|
@required this.appState,
|
||||||
@required this.noteAdder,
|
@required this.noteAdder,
|
||||||
|
@required this.noteRemover,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -47,6 +49,7 @@ class HomeScreen extends StatelessWidget {
|
|||||||
body: new JournalList(
|
body: new JournalList(
|
||||||
notes: appState.notes,
|
notes: appState.notes,
|
||||||
noteSelectedFunction: (note) => _noteSelected(note, context),
|
noteSelectedFunction: (note) => _noteSelected(note, context),
|
||||||
|
noteRemover: noteRemover,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user