NoteViewer: Add a delete action

Having to swipe the note is not obvious.
This commit is contained in:
Vishesh Handa
2019-02-15 12:58:18 +01:00
parent 0ff71dda2b
commit e93e2a2b34

View File

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:journal/state_container.dart';
import 'package:journal/widgets/note_header.dart';
import 'note.dart';
@ -40,17 +41,24 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
return Scaffold(
appBar: AppBar(
title: Text('TIMELINE'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
final stateContainer = StateContainer.of(context);
Note note = widget.notes[_currentIndex()];
stateContainer.removeNote(note);
Navigator.pop(context);
},
),
],
),
body: pageView,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.edit),
onPressed: () {
var route = MaterialPageRoute(builder: (context) {
int currentIndex = pageController.page.toInt();
assert(currentIndex >= 0);
assert(currentIndex < widget.notes.length);
Note note = widget.notes[currentIndex];
Note note = widget.notes[_currentIndex()];
return NoteEditor.fromNote(note);
});
Navigator.of(context).push(route);
@ -58,6 +66,13 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
),
);
}
int _currentIndex() {
int currentIndex = pageController.page.toInt();
assert(currentIndex >= 0);
assert(currentIndex < widget.notes.length);
return currentIndex;
}
}
class NoteViewer extends StatelessWidget {