Flutter:flutter_markdown字体大小

时间:2018-09-05 01:14:09

标签: flutter markdown

使用flutter_markdown时是否可以更改文本的字体大小?类似于将TextStyle提供给Text小部件。谢谢!

5 个答案:

答案 0 :(得分:2)

以下代码缩放所有元素的文本大小:

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

答案 1 :(得分:1)

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>元素)

答案 2 :(得分:1)

在 2021 年,您的主要文本样式是:

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

答案 3 :(得分:0)

存储库中的自述文件表明您可以将MarkDownStyle传递给小部件:

“默认情况下,Markdown使用当前材料设计主题的格式,但是可以创建自己的自定义样式。使用MarkdownStyle类传递您自己的样式。如果您不想在外部使用Markdown材质设计,请使用MarkdownRaw类。”

来源:https://github.com/flutter/flutter_markdown/blob/master/README.md#getting-started

答案 4 :(得分:0)

这对我有用:

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主题数据中的标题来自定义header1。同样,您可以通过修改标题等来自定义h2。