mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
NoteEditor: Show a confirmation dialog if discarding a note
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:journal/note.dart';
|
||||
@ -15,13 +17,43 @@ class NoteEditor extends StatelessWidget {
|
||||
final container = StateContainer.of(context);
|
||||
|
||||
var bodyWidget = new Container(
|
||||
child: new TextFormField(
|
||||
key: noteTextKey,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: 5000,
|
||||
decoration: new InputDecoration(
|
||||
hintText: 'Write here',
|
||||
child: new Form(
|
||||
// Show a dialog if discarding non-empty notes
|
||||
onWillPop: () {
|
||||
return Future(() {
|
||||
var noteContent = noteTextKey.currentState.value.trim();
|
||||
if (noteContent.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text('Are you sure?'),
|
||||
content: new Text('Do you want to discard the entry'),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: new Text('No'),
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: new Text('Yes'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
child: TextFormField(
|
||||
key: noteTextKey,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: 5000,
|
||||
decoration: new InputDecoration(
|
||||
hintText: 'Write here',
|
||||
),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@ -38,10 +70,10 @@ class NoteEditor extends StatelessWidget {
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
var body = noteTextKey.currentState.value;
|
||||
var noteContent = noteTextKey.currentState.value;
|
||||
var note = new Note(
|
||||
createdAt: _createdAt,
|
||||
body: body,
|
||||
body: noteContent,
|
||||
);
|
||||
container.addNote(note);
|
||||
|
||||
|
Reference in New Issue
Block a user