feat: extract markdown view, add basic style

This commit is contained in:
Rongjian Zhang 2019-09-13 16:27:33 +08:00
parent 6312da876a
commit 70f83df1fe
3 changed files with 68 additions and 7 deletions

View File

@ -6,10 +6,10 @@ import 'package:git_touch/models/settings.dart';
import 'package:git_touch/screens/users.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:git_touch/widgets/table_view.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/screens/commits.dart';
import 'package:git_touch/screens/object.dart';
@ -300,7 +300,7 @@ class RepoScreen extends StatelessWidget {
if (payload['object'] != null)
Container(
padding: EdgeInsets.all(16),
child: MarkdownBody(data: payload['object']['text']),
child: MarkdownView(payload['object']['text']),
),
],
);

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:primer/primer.dart';
@ -64,10 +64,7 @@ class CommentItem extends StatelessWidget {
),
]),
SizedBox(height: 12),
MarkdownBody(
data: payload['body'] as String,
// styleSheet: MarkdownStyleSheet(code: TextStyle(fontSize: 14)),
),
MarkdownView(payload['body'] as String),
SizedBox(height: 12),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,

View File

@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:primer/primer.dart';
class MarkdownView extends StatelessWidget {
final String text;
MarkdownView(this.text);
@override
Widget build(BuildContext context) {
return MarkdownBody(
data: text,
styleSheet: MarkdownStyleSheet(
a: TextStyle(fontSize: 16, height: 1.5, color: PrimerColors.blue500),
p: TextStyle(fontSize: 16, height: 1.5, color: PrimerColors.gray900),
code: TextStyle(fontSize: 16, color: PrimerColors.gray900),
h1: TextStyle(
fontSize: 32,
color: PrimerColors.gray900,
fontWeight: FontWeight.w600),
h2: TextStyle(
fontSize: 24,
color: PrimerColors.gray900,
fontWeight: FontWeight.w600),
h3: TextStyle(
fontSize: 20,
color: PrimerColors.gray900,
fontWeight: FontWeight.w600),
h4: TextStyle(
fontSize: 16,
color: PrimerColors.gray900,
fontWeight: FontWeight.w600),
h5: TextStyle(
fontSize: 14,
color: PrimerColors.gray900,
fontWeight: FontWeight.w600),
h6: TextStyle(
fontSize: 13.6,
color: PrimerColors.gray500,
fontWeight: FontWeight.w600),
em: TextStyle(fontStyle: FontStyle.italic),
strong: TextStyle(fontWeight: FontWeight.w600),
blockquote: TextStyle(),
img: TextStyle(),
blockSpacing: 8.0,
listIndent: 32.0,
blockquotePadding: 8.0,
blockquoteDecoration: BoxDecoration(
color: Colors.blue.shade100,
borderRadius: BorderRadius.circular(2.0)),
codeblockPadding: 8.0,
codeblockDecoration: BoxDecoration(
color: Colors.grey.shade100,
borderRadius: BorderRadius.circular(2.0)),
horizontalRuleDecoration: BoxDecoration(
border:
Border(top: BorderSide(width: 5.0, color: Colors.grey.shade300)),
),
),
// syntaxHighlighter: , // TODO:
);
}
}