mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Split NoteViewer into another file
This commit is contained in:
@ -5,21 +5,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'note.dart';
|
||||||
import 'note_editor.dart';
|
import 'note_editor.dart';
|
||||||
|
import 'note_viewer.dart';
|
||||||
class Note {
|
|
||||||
final DateTime createdAt;
|
|
||||||
final String body;
|
|
||||||
|
|
||||||
const Note({this.createdAt, this.body});
|
|
||||||
|
|
||||||
factory Note.fromJson(Map<String, dynamic> json) {
|
|
||||||
return new Note(
|
|
||||||
createdAt: DateTime.parse(json['createdAt']),
|
|
||||||
body: json['body'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<Note>> fetchNotes() async {
|
Future<List<Note>> fetchNotes() async {
|
||||||
final response = await http.get('http://192.168.1.132:8000/notes');
|
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) {
|
void _itemTapped(BuildContext context, Note note) {
|
||||||
// FIXME: Add some kind of a header?
|
var route =
|
||||||
var formatter = new DateFormat('dd MMM, yyyy');
|
new MaterialPageRoute(builder: (context) => new NoteViewer(note: note));
|
||||||
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);
|
|
||||||
Navigator.of(context).push(route);
|
Navigator.of(context).push(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
lib/note.dart
Normal file
13
lib/note.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class Note {
|
||||||
|
final DateTime createdAt;
|
||||||
|
final String body;
|
||||||
|
|
||||||
|
const Note({this.createdAt, this.body});
|
||||||
|
|
||||||
|
factory Note.fromJson(Map<String, dynamic> json) {
|
||||||
|
return new Note(
|
||||||
|
createdAt: DateTime.parse(json['createdAt']),
|
||||||
|
body: json['body'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
31
lib/note_viewer.dart
Normal file
31
lib/note_viewer.dart
Normal file
@ -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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user