diff --git a/lib/note_editor.dart b/lib/note_editor.dart index ed365bee..3bd5c83a 100644 --- a/lib/note_editor.dart +++ b/lib/note_editor.dart @@ -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 { @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 { appBar: new AppBar( title: new Text(title), ), - body: bodyWidget, + body: Padding( + padding: const EdgeInsets.all(8.0), + child: SingleChildScrollView( + child: Column( + children: [ + NoteHeader(note), + bodyWidget, + ], + ), + ), + ), floatingActionButton: FloatingActionButton( child: Icon(Icons.check), onPressed: () { diff --git a/lib/note_viewer.dart b/lib/note_viewer.dart index 47e02a83..20766a1a 100644 --- a/lib/note_viewer.dart +++ b/lib/note_viewer.dart @@ -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: [ - _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: [ - bigNum, - new Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Column( - children: [ - 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), diff --git a/lib/widgets/note_header.dart b/lib/widgets/note_header.dart new file mode 100644 index 00000000..a712d3d9 --- /dev/null +++ b/lib/widgets/note_header.dart @@ -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: [ + bigNum, + new Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Column( + children: [ + dateText, + timeText, + ], + crossAxisAlignment: CrossAxisAlignment.start, + ), + ), + ], + ); + + return new Padding( + padding: new EdgeInsets.only(top: 6.0, bottom: 6.0 * 3), + child: w, + ); + } +}