Flutter:如何在使用 flutter_markdown 库时更改超链接的颜色并添加下划线

问题描述 投票:0回答:2

我正在使用 flutter_markdown 库来显示 markdown 文本,对我来说,每次超链接都以默认的颤动蓝色显示,我尝试更改 ThemeData 应用程序颜色,但没有帮助,基本上我需要的是将超链接的颜色从蓝色更改为绿色并添加下划线。

这可能吗?如果没有,请建议一些替代方法如何实现它

我正在使用此代码:

_showMarkdownTestModal() {
    var testMarkdown = '[flutter_markdown](https://github.com/DavBfr/flutter_markdown)';
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        isScrollControlled: true,
        builder: (builder) {
          return FractionallySizedBox(
              heightFactor: 0.1,
              child: Center(
                  child: MarkdownBody(
                data: testMarkdown,
                onTapLink: (text, url, title) {
                  if (url != null) {
                    _launchURL(Uri.parse(url));
                  }
                },
              )));
        });
  }

预先感谢您的帮助

flutter dart hyperlink markdown
2个回答
2
投票

就像这样:

MarkdownBody(
  styleSheet: MarkdownStyleSheet(
    a: const TextStyle(
      color: Colors.red,
      decoration: TextDecoration.underline,
    ),
    // ...
  ),
  // ...
);

0
投票

虽然接受的答案适用于文本颜色,但它忽略了下划线颜色。如果你想在那里使用相同的颜色,也可以这样声明:

TextStyle(
  color: Colors.red,
  decoration: TextDecoration.underline,
  decorationColor: Colors.red,
)
© www.soinside.com 2019 - 2024. All rights reserved.