diff --git a/lib/screens/journal_browsing.dart b/lib/screens/journal_browsing.dart index f1d22182..64d13d96 100644 --- a/lib/screens/journal_browsing.dart +++ b/lib/screens/journal_browsing.dart @@ -1,16 +1,14 @@ import 'package:fimber/fimber.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:page_transition/page_transition.dart'; import 'package:share/share.dart'; -import 'package:url_launcher/url_launcher.dart'; import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/utils.dart'; -import 'package:gitjournal/widgets/journal_editor_header.dart'; import 'package:gitjournal/widgets/rename_dialog.dart'; +import 'package:gitjournal/widgets/note_viewer.dart'; import 'journal_editor.dart'; @@ -162,109 +160,3 @@ class JournalBrowsingScreenState extends State { ); } } - -class NoteViewer extends StatelessWidget { - final Note note; - const NoteViewer({Key key, @required this.note}) : super(key: key); - - final bool showJournalHeader = false; - final bool showTitle = true; - - @override - Widget build(BuildContext context) { - ThemeData theme = Theme.of(context); - theme = theme.copyWith( - textTheme: theme.textTheme.copyWith( - body1: theme.textTheme.subhead, - ), - ); - - // Copied from MarkdownStyleSheet except Grey is replaced with Highlight color - var markdownStyleSheet = MarkdownStyleSheet.fromTheme(theme).copyWith( - code: theme.textTheme.body1.copyWith( - backgroundColor: theme.dialogBackgroundColor, - fontFamily: "monospace", - fontSize: theme.textTheme.body1.fontSize * 0.85, - ), - tableBorder: TableBorder.all(color: theme.highlightColor, width: 0), - tableCellsDecoration: BoxDecoration(color: theme.dialogBackgroundColor), - codeblockDecoration: BoxDecoration( - color: theme.dialogBackgroundColor, - borderRadius: BorderRadius.circular(2.0), - ), - horizontalRuleDecoration: BoxDecoration( - border: Border( - top: BorderSide(width: 5.0, color: theme.highlightColor), - ), - ), - ); - - var view = SingleChildScrollView( - child: Column( - children: [ - if (note.created != null && showJournalHeader) - JournalEditorHeader(note), - if (showTitle && note.title.isNotEmpty) - NoteTitleHeader(note.title), - Padding( - padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), - child: MarkdownBody( - data: note.body, - styleSheet: markdownStyleSheet, - onTapLink: (String link) { - print("Launching " + link); - launch(link); - }, - ), - ), - const SizedBox(height: 64.0), - // _buildFooter(context), - ], - crossAxisAlignment: CrossAxisAlignment.start, - ), - padding: const EdgeInsets.all(16.0), - ); - - return Hero(tag: note.filePath, child: view); - } - - /* - Widget _buildFooter(BuildContext context) { - return Padding( - padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), - child: Row( - children: [ - IconButton( - icon: Icon(Icons.arrow_left), - tooltip: 'Previous Entry', - onPressed: showPrevNoteFunc, - ), - Expanded( - flex: 10, - child: Text(''), - ), - IconButton( - icon: Icon(Icons.arrow_right), - tooltip: 'Next Entry', - onPressed: showNextNoteFunc, - ), - ], - ), - ); - } - */ -} - -class NoteTitleHeader extends StatelessWidget { - final String header; - NoteTitleHeader(this.header); - - @override - Widget build(BuildContext context) { - var textTheme = Theme.of(context).textTheme; - return Padding( - padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), - child: Text(header, style: textTheme.title), - ); - } -} diff --git a/lib/widgets/note_viewer.dart b/lib/widgets/note_viewer.dart new file mode 100644 index 00000000..2a6306c3 --- /dev/null +++ b/lib/widgets/note_viewer.dart @@ -0,0 +1,113 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:url_launcher/url_launcher.dart'; + +import 'package:gitjournal/core/note.dart'; +import 'package:gitjournal/widgets/journal_editor_header.dart'; + +class NoteViewer extends StatelessWidget { + final Note note; + const NoteViewer({Key key, @required this.note}) : super(key: key); + + final bool showJournalHeader = false; + final bool showTitle = true; + + @override + Widget build(BuildContext context) { + ThemeData theme = Theme.of(context); + theme = theme.copyWith( + textTheme: theme.textTheme.copyWith( + body1: theme.textTheme.subhead, + ), + ); + + // Copied from MarkdownStyleSheet except Grey is replaced with Highlight color + var markdownStyleSheet = MarkdownStyleSheet.fromTheme(theme).copyWith( + code: theme.textTheme.body1.copyWith( + backgroundColor: theme.dialogBackgroundColor, + fontFamily: "monospace", + fontSize: theme.textTheme.body1.fontSize * 0.85, + ), + tableBorder: TableBorder.all(color: theme.highlightColor, width: 0), + tableCellsDecoration: BoxDecoration(color: theme.dialogBackgroundColor), + codeblockDecoration: BoxDecoration( + color: theme.dialogBackgroundColor, + borderRadius: BorderRadius.circular(2.0), + ), + horizontalRuleDecoration: BoxDecoration( + border: Border( + top: BorderSide(width: 5.0, color: theme.highlightColor), + ), + ), + ); + + var view = SingleChildScrollView( + child: Column( + children: [ + if (note.created != null && showJournalHeader) + JournalEditorHeader(note), + if (showTitle && note.title.isNotEmpty) + NoteTitleHeader(note.title), + Padding( + padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), + child: MarkdownBody( + data: note.body, + styleSheet: markdownStyleSheet, + onTapLink: (String link) { + print("Launching " + link); + launch(link); + }, + ), + ), + const SizedBox(height: 64.0), + // _buildFooter(context), + ], + crossAxisAlignment: CrossAxisAlignment.start, + ), + padding: const EdgeInsets.all(16.0), + ); + + return Hero(tag: note.filePath, child: view); + } + + /* + Widget _buildFooter(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), + child: Row( + children: [ + IconButton( + icon: Icon(Icons.arrow_left), + tooltip: 'Previous Entry', + onPressed: showPrevNoteFunc, + ), + Expanded( + flex: 10, + child: Text(''), + ), + IconButton( + icon: Icon(Icons.arrow_right), + tooltip: 'Next Entry', + onPressed: showNextNoteFunc, + ), + ], + ), + ); + } + */ +} + +class NoteTitleHeader extends StatelessWidget { + final String header; + NoteTitleHeader(this.header); + + @override + Widget build(BuildContext context) { + var textTheme = Theme.of(context).textTheme; + return Padding( + padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), + child: Text(header, style: textTheme.title), + ); + } +}