Bor*_*ayi 3 markdown android ios dart flutter
我想在读取 Markdown 小部件的屏幕底部添加一个超链接。我试图在 Markdown 文件中包含超链接,但 flutter 没有启动它。
然后我尝试了这个:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Protective measures'),
),
body: Column(
children: <Widget>[
Flexible(
child: FutureBuilder(
future: DefaultAssetBundle.of(context)
.loadString("assets/docs/protective_measures.md"),
builder:
(BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Markdown(
data: snapshot.data,
styleSheet: MarkdownStyleSheet(
textAlign: WrapAlignment.start,
p: TextStyle(
fontSize: 16,
color: isDark ? Colors.white : Colors.black,
),
h2: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
h1: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
color: isDark ? Colors.white : Colors.black,
),
),
);
}
return Center(
child: CircularProgressIndicator(),
);
},
),
),
InkWell(
child: Text(
'My Hyperlink',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.blue,
decoration: TextDecoration.underline
),
),
onTap: () => launch('https://stackoverflow.com'),
),
],
),
);
}
Run Code Online (Sandbox Code Playgroud)
结果并不是我想要的。我想在屏幕底部有一个超文本,就在 Markdown 之后。我也尝试过使用 ListView 而不是 Column 但它不起作用。
任何提示?
对于插件flutter_markdown你可以这样做
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
final String _markdownData = "-This is [Google link](https://www.google.com)";
// view
MarkdownBody(
data: _markdownData,
onTapLink: (text, url, title){
launch(url);
},
)
Run Code Online (Sandbox Code Playgroud)
更新flutter_markdown 0.5.1 或更低版本:
MarkdownBody(
data: _markdownData,
onTapLink: (url) {
launch(url);
},
)
Run Code Online (Sandbox Code Playgroud)