mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
NoteEditor: Remove floating action button
It comes in the way of writing.
This commit is contained in:
@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import 'package:journal/state_container.dart';
|
import 'package:journal/state_container.dart';
|
||||||
@ -37,25 +35,6 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var bodyWidget = Form(
|
var bodyWidget = Form(
|
||||||
// Show a dialog if discarding non-empty notes
|
|
||||||
onWillPop: () {
|
|
||||||
return Future(() {
|
|
||||||
var noteContent = _textController.text.trim();
|
|
||||||
if (noteContent.isEmpty) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (note != null) {
|
|
||||||
if (noteContent == note.body) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: _buildAlertDialog,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
@ -73,6 +52,31 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
var newJournalScreen = Scaffold(
|
var newJournalScreen = Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(title),
|
title: Text(title),
|
||||||
|
leading: IconButton(
|
||||||
|
icon: Icon(Icons.check),
|
||||||
|
onPressed: () {
|
||||||
|
final stateContainer = StateContainer.of(context);
|
||||||
|
this.note.body = _textController.text;
|
||||||
|
if (this.note.body.isNotEmpty) {
|
||||||
|
newNote
|
||||||
|
? stateContainer.addNote(note)
|
||||||
|
: stateContainer.updateNote(note);
|
||||||
|
}
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.close),
|
||||||
|
onPressed: () {
|
||||||
|
if (_noteModified()) {
|
||||||
|
showDialog(context: context, builder: _buildAlertDialog);
|
||||||
|
} else {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
@ -85,17 +89,6 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
child: Icon(Icons.check),
|
|
||||||
onPressed: () {
|
|
||||||
final stateContainer = StateContainer.of(context);
|
|
||||||
this.note.body = _textController.text;
|
|
||||||
|
|
||||||
newNote
|
|
||||||
? stateContainer.addNote(note)
|
|
||||||
: stateContainer.updateNote(note);
|
|
||||||
Navigator.pop(context);
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return newJournalScreen;
|
return newJournalScreen;
|
||||||
@ -116,10 +109,25 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
child: Text('No'),
|
child: Text('No'),
|
||||||
),
|
),
|
||||||
FlatButton(
|
FlatButton(
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () {
|
||||||
|
Navigator.pop(context); // Alert box
|
||||||
|
Navigator.pop(context); // Note Editor
|
||||||
|
},
|
||||||
child: Text('Yes'),
|
child: Text('Yes'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _noteModified() {
|
||||||
|
var noteContent = _textController.text.trim();
|
||||||
|
if (noteContent.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (note != null) {
|
||||||
|
return noteContent != note.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user