mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +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:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
@ -15,7 +17,36 @@ class NoteEditor extends StatelessWidget {
|
|||||||
final container = StateContainer.of(context);
|
final container = StateContainer.of(context);
|
||||||
|
|
||||||
var bodyWidget = new Container(
|
var bodyWidget = new Container(
|
||||||
child: new TextFormField(
|
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,
|
key: noteTextKey,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
@ -24,6 +55,7 @@ class NoteEditor extends StatelessWidget {
|
|||||||
hintText: 'Write here',
|
hintText: 'Write here',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -38,10 +70,10 @@ class NoteEditor extends StatelessWidget {
|
|||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var body = noteTextKey.currentState.value;
|
var noteContent = noteTextKey.currentState.value;
|
||||||
var note = new Note(
|
var note = new Note(
|
||||||
createdAt: _createdAt,
|
createdAt: _createdAt,
|
||||||
body: body,
|
body: noteContent,
|
||||||
);
|
);
|
||||||
container.addNote(note);
|
container.addNote(note);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user