mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Note Editing: Add the NoteHeader
It looks much prettier this way.
This commit is contained in:
@ -1,9 +1,10 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import 'package:journal/state_container.dart';
|
import 'package:journal/state_container.dart';
|
||||||
|
import 'package:journal/widgets/note_header.dart';
|
||||||
|
|
||||||
class NoteEditor extends StatefulWidget {
|
class NoteEditor extends StatefulWidget {
|
||||||
final Note note;
|
final Note note;
|
||||||
@ -37,8 +38,7 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var bodyWidget = new Container(
|
var bodyWidget = Form(
|
||||||
child: new Form(
|
|
||||||
// Show a dialog if discarding non-empty notes
|
// Show a dialog if discarding non-empty notes
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
return Future(() {
|
return Future(() {
|
||||||
@ -55,14 +55,13 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
maxLines: 5000,
|
maxLines: null,
|
||||||
decoration: new InputDecoration(
|
decoration: new InputDecoration(
|
||||||
hintText: 'Write here',
|
hintText: 'Write here',
|
||||||
|
border: InputBorder.none,
|
||||||
),
|
),
|
||||||
controller: _textController,
|
controller: _textController,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var title = newNote ? "New Journal Entry" : "Edit Journal Entry";
|
var title = newNote ? "New Journal Entry" : "Edit Journal Entry";
|
||||||
@ -70,7 +69,17 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
appBar: new AppBar(
|
appBar: new AppBar(
|
||||||
title: new Text(title),
|
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(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.check),
|
child: Icon(Icons.check),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
|
|
||||||
import 'package:journal/widgets/swipe_detector.dart';
|
import 'package:journal/widgets/swipe_detector.dart';
|
||||||
|
import 'package:journal/widgets/note_header.dart';
|
||||||
|
|
||||||
import 'note_editor.dart';
|
import 'note_editor.dart';
|
||||||
import 'note.dart';
|
import 'note.dart';
|
||||||
@ -79,9 +79,9 @@ class NoteViewer extends StatelessWidget {
|
|||||||
var view = new SingleChildScrollView(
|
var view = new SingleChildScrollView(
|
||||||
child: new Column(
|
child: new Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildHeader(context),
|
NoteHeader(note),
|
||||||
new Text(note.body, style: _biggerFont),
|
Text(note.body, style: _biggerFont),
|
||||||
_buildFooter(context),
|
// _buildFooter(context),
|
||||||
],
|
],
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
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) {
|
Widget _buildFooter(BuildContext context) {
|
||||||
return new Padding(
|
return new Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
||||||
|
52
lib/widgets/note_header.dart
Normal file
52
lib/widgets/note_header.dart
Normal 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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user