mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-25 11:57:18 +08:00
Split NoteViewer into its own file
This commit is contained in:
lib
@ -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<JournalBrowsingScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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: <Widget>[
|
||||
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: <Widget>[
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
113
lib/widgets/note_viewer.dart
Normal file
113
lib/widgets/note_viewer.dart
Normal file
@ -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: <Widget>[
|
||||
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: <Widget>[
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user