【问题标题】:flutter: Custom font showing no effect颤振:自定义字体显示没有效果
【发布时间】:2019-01-11 14:20:10
【问题描述】:

我在 SO 上尝试了许多解决方案,但没有一个有效,我尝试了这些解决方案 here,here,但字体仍然没有效果,应用程序也没有显示任何错误。 代码有什么问题。

这是我下面的代码

  Widget textSection = new Container(
  decoration: new BoxDecoration(
      color: Colors.blue[100], border: new Border.all(color: Colors.black)),
  padding: const EdgeInsets.all(18.0),
  margin: const EdgeInsets.only(left: 14.0, right: 14.0, bottom: 14.0),
  width: double.infinity,
  child: new Text(
    "Labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
    textAlign: TextAlign.center,
    style: new TextStyle(
        color: Colors.black45,
        fontSize: 22.0,
        fontFamily: 'Raleway-Regular'),
    softWrap: true,
  ),
);

【问题讨论】:

  • 你能把你的pubspec.yaml文件贴出来(代码格式)
  • 更正您的身份并运行flutter clean,确保创建一个新的/build 文件夹

标签: android fonts dart flutter


【解决方案1】:

我实际上也在我的应用程序中使用了这种精确的字体。我认为您需要为此购买许可证,但我不记得了。无论如何,你的字体名称在这里:

fonts:
    family: Raleway

在这里,您将字体命名为 Raleway,因此在您的 Flutter 代码中,您必须指定 准确 相同的名称:

fontFamily: 'Raleway'

【讨论】:

    【解决方案2】:

    我认为它与您的 pubspec 文件有关,缩进很重要。

    flutter:
      uses-material-design: true
      assets: 
        - image/lake.png
      fonts:
        - family: Raleway
          fonts:
            - asset: fonts/Raleway-Regular.ttf
            - asset: fonts/Raleway-Italic.ttf
              style: italic
    

    【讨论】:

      【解决方案3】:

      您将字体系列命名为 Raleway,但在代码中使用了字符串 Raleway-Regular。将其中一个更改为另一个,它应该可以工作。

      【讨论】:

        猜你喜欢
        • 2020-08-11
        • 2019-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 1970-01-01
        相关资源
        最近更新 更多