note edit: rename by clicking appbar

master
EmaMaker 2021-09-21 22:14:11 +02:00
parent 1997677fb2
commit 918d6c4f88
2 changed files with 52 additions and 1 deletions

View File

@ -82,6 +82,11 @@ class CounterStorage {
f.rename('$dir/$newName');
}
void saveRename(String oldName, String content, String newName) async {
await saveNote(oldName, content);
renameNote(oldName, newName);
}
// Note: Name of the note/filepath. If "" create a new note
void openNote(BuildContext context, String note) {
Navigator.pushReplacement(

View File

@ -15,13 +15,14 @@ class NewNote extends StatefulWidget {
class _NewNoteState extends State<NewNote> {
bool _changed = false;
String _title = "New Note";
late TextEditingController _controllerNote;
late TextEditingController _controllerNote, _controller;
@override
void initState() {
super.initState();
_controllerNote = TextEditingController();
_controller = TextEditingController();
if (widget.note != "") {
widget.storage.getNote(widget.note).then((String value) {
@ -49,6 +50,7 @@ class _NewNoteState extends State<NewNote> {
toolbarHeight: 50,
title: InkWell(
child: Text("$_title"),
onTap: () => _changeTitleDialog(context),
),
centerTitle: true,
leading: new IconButton(
@ -80,6 +82,50 @@ class _NewNoteState extends State<NewNote> {
});
}
void _changeTitleDialog(BuildContext context) {
// debugdebugPrint("Clicked title");
showDialog (
context: context,
builder: (BuildContext ctx) {
return AlertDialog(
title: Text('Rename note:'),
content: TextField(
controller: _controller,
maxLines: 1,
decoration: InputDecoration(
hintText: _title,
),
),
actions: [
TextButton(
onPressed: () {
setState(() {
Navigator.pop(context);
_controller.text = "";
});
},
child: Text('No')),
TextButton(
onPressed: () {
if (_controller.text != "") {
setState(() {
Navigator.pop(context);
print(_title);
//Note: code repetition
_changed = false;
widget.storage.saveRename(_title, _controllerNote.text, _controller.text);
_title = _controller.text;
_controller.text = "";
});
}
},
child: Text('Yes')),
],
);
});
}
void _deleteDialog(BuildContext context) {
if (_changed)
showDialog(