Flutter:flutter_markdown字体大小

18

在使用flutter_markdown时,是否有办法更改文本的字体大小?类似于向Text小部件提供TextStyle那样。谢谢!

4个回答

24
Markdown(
    data: html2md.convert(article.content),
    styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context))
                    .copyWith(
                       p: Theme.of(context).textTheme.body1.copyWith(fontSize: 12.0)
                    ),
)

您可以在Markdown中覆盖特定元素的文本样式,上面的代码示例用于覆盖Markdown中的p元素(在html中为<p>元素)。


13

2021年样式主文本的方法是:

Markdown(
    data: "This is the *way*",
    styleSheet: MarkdownStyleSheet.fromTheme(ThemeData(
      textTheme: TextTheme(
          bodyText2: TextStyle(
              fontSize: 20.0, color: Colors.green)))))),

嗨Christian,你也知道如何更改可点击文本的样式吗?这里有关于这个问题的更多细节。 - undefined

13

以下代码会调整所有元素中的文本大小:

Markdown(
  styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context))
      .copyWith(textScaleFactor: 1.5),
  data: md,
);

嗨k2s,你也知道如何更改可点击文本的样式吗?以下是有关问题的更多详细信息。 - undefined

2
这对我有效:
theme:new ThemeData(
  backgroundColor: Colors.black26,primarySwatch: Colors.grey,
  textTheme: TextTheme(body1: TextStyle(fontSize: 25.0),
  headline: TextStyle(fontSize: 25.0),title: TextStyle(fontSize: 30.0))
),

你可以查看Markdown Github仓库中提供的StyleSheet类。基本上,这段代码是我的备忘单:
  p: theme.textTheme.body1,
  h1 theme.textTheme.headline,
  h2: theme.textTheme.title,
  h3: theme.textTheme.subhead,
  h4: theme.textTheme.body2,
  h5: theme.textTheme.body2,
  h6: theme.textTheme.body2,

您可以通过在MaterialApp的themedata中修改headline来自定义header1。同样地,您可以通过修改title等来自定义h2。

嗨Foxy,你也知道如何更改可点击文本的样式吗?以下是有关问题的更多详细信息。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接