【问题标题】:Importing and using custom font is not working导入和使用自定义字体不起作用
【发布时间】:2020-03-30 03:31:40
【问题描述】:

我使用 Android Studio 作为我的 IDE。现在,我正在尝试使用自定义字体。但是我的代码不起作用。这是我到目前为止所做的。我从 fonts.google.com 下载字体并将 TTF 文件导入到我的项目中,在我的项目根文件夹下创建了一个名为 fonts 的新文件夹。

然后我将以下代码添加到我的 pubspec.yml 文件中。

fonts:
    - family: Roboto
      fonts:
        - asset: fonts/Roboto-Regular.ttf
        - asset: fonts/Roboto-Bold.ttf
          weight: 400

然后我将自定义字体设置为 Text 小部件,如下所示。

Text("Flight", textDirection: TextDirection.ltr,style: TextStyle(fontSize: 40.0, color: Colors.white, fontFamily: "Roboto", fontWeight: FontWeight.w400),)

当我启动应用程序时,它不起作用。字体没有改变。我的代码有什么问题,我该如何解决?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    在 pubspec.yml 中添加代码后,您应该在终端中运行flutter pub get。此命令获取 pubspec.yaml 中列出的所有依赖项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 2012-04-22
      • 1970-01-01
      • 2015-11-08
      相关资源
      最近更新 更多