Note Editing: Add the NoteHeader

It looks much prettier this way.
This commit is contained in:
Vishesh Handa
2019-01-15 13:59:58 +01:00
parent 7e084ac0e9
commit a29389d4bb
3 changed files with 91 additions and 71 deletions

View File

@ -1,9 +1,10 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:journal/note.dart';
import 'package:journal/state_container.dart';
import 'package:journal/widgets/note_header.dart';
class NoteEditor extends StatefulWidget {
final Note note;
@ -37,32 +38,30 @@ class NoteEditorState extends State<NoteEditor> {
@override
Widget build(BuildContext context) {
var bodyWidget = new Container(
child: new Form(
// Show a dialog if discarding non-empty notes
onWillPop: () {
return Future(() {
var noteContent = _textController.text.trim();
if (noteContent.isEmpty) {
return true;
}
return showDialog(
context: context,
builder: _buildAlertDialog,
);
});
},
child: TextFormField(
autofocus: true,
keyboardType: TextInputType.multiline,
maxLines: 5000,
decoration: new InputDecoration(
hintText: 'Write here',
),
controller: _textController,
var bodyWidget = Form(
// Show a dialog if discarding non-empty notes
onWillPop: () {
return Future(() {
var noteContent = _textController.text.trim();
if (noteContent.isEmpty) {
return true;
}
return showDialog(
context: context,
builder: _buildAlertDialog,
);
});
},
child: TextFormField(
autofocus: true,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: new InputDecoration(
hintText: 'Write here',
border: InputBorder.none,
),
controller: _textController,
),
padding: const EdgeInsets.all(8.0),
);
var title = newNote ? "New Journal Entry" : "Edit Journal Entry";
@ -70,7 +69,17 @@ class NoteEditorState extends State<NoteEditor> {
appBar: new AppBar(
title: new Text(title),
),
body: bodyWidget,
body: Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
NoteHeader(note),
bodyWidget,
],
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.check),
onPressed: () {

View File

@ -1,8 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:journal/widgets/swipe_detector.dart';
import 'package:journal/widgets/note_header.dart';
import 'note_editor.dart';
import 'note.dart';
@ -79,9 +79,9 @@ class NoteViewer extends StatelessWidget {
var view = new SingleChildScrollView(
child: new Column(
children: <Widget>[
_buildHeader(context),
new Text(note.body, style: _biggerFont),
_buildFooter(context),
NoteHeader(note),
Text(note.body, style: _biggerFont),
// _buildFooter(context),
],
crossAxisAlignment: CrossAxisAlignment.start,
),
@ -95,47 +95,6 @@ class NoteViewer extends StatelessWidget {
);
}
Widget _buildHeader(BuildContext context) {
var dateStr = DateFormat('MMM, yyyy').format(note.created);
var timeStr = DateFormat('EEEE H:m').format(note.created);
var bigNum = new Text(
note.created.day.toString(),
style: TextStyle(fontSize: 40.0),
);
var dateText = new Text(
dateStr,
style: TextStyle(fontSize: 18.0),
);
var timeText = new Text(
timeStr,
style: TextStyle(fontSize: 18.0),
);
var w = new Row(
children: <Widget>[
bigNum,
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Column(
children: <Widget>[
dateText,
timeText,
],
crossAxisAlignment: CrossAxisAlignment.start,
),
),
],
);
return new Padding(
padding: new EdgeInsets.only(top: 6.0, bottom: 6.0 * 3),
child: w,
);
}
Widget _buildFooter(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),

View File

@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:journal/note.dart';
class NoteHeader extends StatelessWidget {
final Note note;
NoteHeader(this.note);
@override
Widget build(BuildContext context) {
var dateStr = DateFormat('MMM, yyyy').format(note.created);
var timeStr = DateFormat('EEEE H:m').format(note.created);
var bigNum = new Text(
note.created.day.toString(),
style: TextStyle(fontSize: 40.0),
);
var dateText = new Text(
dateStr,
style: TextStyle(fontSize: 18.0),
);
var timeText = new Text(
timeStr,
style: TextStyle(fontSize: 18.0),
);
var w = new Row(
children: <Widget>[
bigNum,
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Column(
children: <Widget>[
dateText,
timeText,
],
crossAxisAlignment: CrossAxisAlignment.start,
),
),
],
);
return new Padding(
padding: new EdgeInsets.only(top: 6.0, bottom: 6.0 * 3),
child: w,
);
}
}