mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
NoteViewer: Add a delete action
Having to swipe the note is not obvious.
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:journal/state_container.dart';
|
||||||
import 'package:journal/widgets/note_header.dart';
|
import 'package:journal/widgets/note_header.dart';
|
||||||
|
|
||||||
import 'note.dart';
|
import 'note.dart';
|
||||||
@ -40,17 +41,24 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('TIMELINE'),
|
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,
|
body: pageView,
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.edit),
|
child: Icon(Icons.edit),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var route = MaterialPageRoute(builder: (context) {
|
var route = MaterialPageRoute(builder: (context) {
|
||||||
int currentIndex = pageController.page.toInt();
|
Note note = widget.notes[_currentIndex()];
|
||||||
assert(currentIndex >= 0);
|
|
||||||
assert(currentIndex < widget.notes.length);
|
|
||||||
|
|
||||||
Note note = widget.notes[currentIndex];
|
|
||||||
return NoteEditor.fromNote(note);
|
return NoteEditor.fromNote(note);
|
||||||
});
|
});
|
||||||
Navigator.of(context).push(route);
|
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 {
|
class NoteViewer extends StatelessWidget {
|
||||||
|
Reference in New Issue
Block a user