feat: handle svg images

This commit is contained in:
Rongjian Zhang 2020-10-04 22:55:45 +08:00
parent 9fd05797b9
commit 8a490abb10
1 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_svg/svg.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/utils/utils.dart';
@ -28,6 +29,19 @@ class MarkdownView extends StatelessWidget {
_basicStyle.copyWith(fontWeight: FontWeight.w600, height: 1.25);
return MarkdownBody(
data: text,
selectable: true,
imageBuilder: (uri, title, alt) {
if (uri.scheme == 'http' || uri.scheme == 'https') {
if (uri.path.endsWith('.svg')) {
return SvgPicture.network(uri.toString());
} else {
return Image.network(uri.toString());
}
} else {
return Container();
}
},
onTapLink: (url) {
final theme = context.read<ThemeModel>();
@ -63,7 +77,6 @@ class MarkdownView extends StatelessWidget {
launchUrl(url);
},
data: text,
styleSheet: MarkdownStyleSheet(
a: _basicStyle.copyWith(color: theme.palette.primary),
p: _basicStyle,