From 8adfb776d02f6eabcf49fe98104274513ffc97bc Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 17 May 2018 18:22:39 +0200 Subject: [PATCH] Split NoteViewer into another file --- lib/main.dart | 35 ++++------------------------------- lib/note.dart | 13 +++++++++++++ lib/note_viewer.dart | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 lib/note.dart create mode 100644 lib/note_viewer.dart diff --git a/lib/main.dart b/lib/main.dart index bc72e522..cb3a0efe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,21 +5,9 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; +import 'note.dart'; import 'note_editor.dart'; - -class Note { - final DateTime createdAt; - final String body; - - const Note({this.createdAt, this.body}); - - factory Note.fromJson(Map json) { - return new Note( - createdAt: DateTime.parse(json['createdAt']), - body: json['body'], - ); - } -} +import 'note_viewer.dart'; Future> fetchNotes() async { final response = await http.get('http://192.168.1.132:8000/notes'); @@ -90,23 +78,8 @@ class JournalList extends StatelessWidget { } void _itemTapped(BuildContext context, Note note) { - // FIXME: Add some kind of a header? - var formatter = new DateFormat('dd MMM, yyyy'); - var title = formatter.format(note.createdAt); - - var bodyWidget = new SingleChildScrollView( - child: new Text(note.body, style: _biggerFont), - padding: const EdgeInsets.all(8.0), - ); - - var showJournalScreen = new Scaffold( - appBar: new AppBar( - title: new Text(title), - ), - body: bodyWidget, - ); - - var route = new MaterialPageRoute(builder: (context) => showJournalScreen); + var route = + new MaterialPageRoute(builder: (context) => new NoteViewer(note: note)); Navigator.of(context).push(route); } diff --git a/lib/note.dart b/lib/note.dart new file mode 100644 index 00000000..dd8f772e --- /dev/null +++ b/lib/note.dart @@ -0,0 +1,13 @@ +class Note { + final DateTime createdAt; + final String body; + + const Note({this.createdAt, this.body}); + + factory Note.fromJson(Map json) { + return new Note( + createdAt: DateTime.parse(json['createdAt']), + body: json['body'], + ); + } +} diff --git a/lib/note_viewer.dart b/lib/note_viewer.dart new file mode 100644 index 00000000..cb76bc0e --- /dev/null +++ b/lib/note_viewer.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +import 'note.dart'; + +class NoteViewer extends StatelessWidget { + final Note note; + final _biggerFont = const TextStyle(fontSize: 18.0); + + const NoteViewer({this.note}); + + @override + Widget build(BuildContext context) { + // FIXME: Add some kind of a header? + + var formatter = new DateFormat('dd MMM, yyyy'); + var title = formatter.format(note.createdAt); + + var bodyWidget = new SingleChildScrollView( + child: new Text(note.body, style: _biggerFont), + padding: const EdgeInsets.all(8.0), + ); + + return new Scaffold( + appBar: new AppBar( + title: new Text(title), + ), + body: bodyWidget, + ); + } +}