6

我正在尝试更改 Flutter for Web Application 中标题的字体,我该怎么做?我发现 pubsec.yaml 与移动版完全不同,这里是文件:

name: projectbaseclient
description: An app built using Flutter for web

environment:
  # You must be using Flutter >=1.5.0 or Dart >=2.3.0
  sdk: '>=2.3.0 <3.0.0'

dependencies:
  flutter_web: any
  flutter_web_ui: any

dev_dependencies:
  build_runner: ^1.5.0
  build_web_compilers: ^2.1.0
  pedantic: ^1.7.0

dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web_ui

这是 FontManifest.json:

[
    {
      "family": "Poppins",
      "fonts": [
        {
          "asset": "fonts/Poppins-Regular.ttf"
        }
      ]
    },
    {
      "family": "KronaOne",
      "fonts": [
        {
          "asset": "fonts/KronaOne-Regular.ttf"
        }
      ]
    },
    {
      "family": "Ubuntu",
      "fonts": [
        {
          "asset": "fonts/Ubuntu-Regular.ttf"
        }
      ]
    }
  ]

我已经创建了一个文件夹 assets/fonts 并在文件夹中添加了字体,我还创建了 FontManifest.json 并将其放在 assets 文件夹中,但是代码不起作用,当我更改文本中的 fontFamily 参数时,它给了我错误目的。

如何将字体用于 Flutter for Web 项目?

4

1 回答 1

7

检查assets文件夹是否位于web文件夹中。接下来,将FontManifest.json内容与以下示例进行比较:

[
  {
    "family": "Rubik",
    "fonts": [
      {
        "asset": "fonts/Rubik-Regular.ttf"
      },
      {
        "asset": "fonts/Rubik-Medium.ttf",
        "weight": 500
      }
    ]
  }
]

更新

由于Flutter for web项目目前已与主Flutter存储库合并,因此不再推荐使用此方法。在web文件夹FontManifest.json文件中创建与由编译器创建的文件冲突。在pubspec.yaml文件中指定字体。

于 2019-07-14T06:27:50.067 回答