mirror of
https://github.com/krawieck/lemmur/
synced 2024-12-14 01:25:13 +01:00
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
import 'package:markdown/markdown.dart' as md;
|
|
|
|
import '../url_launcher.dart';
|
|
import 'fullscreenable_image.dart';
|
|
|
|
/// A Markdown renderer with link/image handling
|
|
class MarkdownText extends StatelessWidget {
|
|
final String instanceUrl;
|
|
final String text;
|
|
final bool selectable;
|
|
|
|
MarkdownText(this.text, {@required this.instanceUrl, this.selectable = false})
|
|
: assert(instanceUrl != null);
|
|
|
|
@override
|
|
Widget build(BuildContext context) => MarkdownBody(
|
|
selectable: selectable,
|
|
data: text,
|
|
extensionSet: md.ExtensionSet.gitHubWeb,
|
|
onTapLink: (href) {
|
|
linkLauncher(context: context, url: href, instanceUrl: instanceUrl)
|
|
.catchError((e) => Scaffold.of(context).showSnackBar(SnackBar(
|
|
content: Row(
|
|
children: [
|
|
Icon(Icons.warning),
|
|
Text("couldn't open link, ${e.toString()}"),
|
|
],
|
|
),
|
|
)));
|
|
},
|
|
imageBuilder: (uri, title, alt) => FullscreenableImage(
|
|
url: uri.toString(),
|
|
child: CachedNetworkImage(
|
|
imageUrl: uri.toString(),
|
|
errorWidget: (context, url, error) => Row(
|
|
children: [
|
|
Icon(Icons.warning),
|
|
Text("couldn't load image, ${error.toString()}")
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|