如何更改Flutter for Web Font? [英] How to change Flutter for web Font?

查看:666
本文介绍了如何更改Flutter for Web Font?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to change the font of the title in my Flutter for Web Application how can i do it? I found out that the pubsec.yaml is completely different than the mobile version here is the file:

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:

This is the 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"
        }
      ]
    }
  ]

我已经创建了一个文件夹asset/fonts,并在该文件夹中添加了字体,我也创建了FontManifest.json并将其放在assets文件夹中,但是它的代码无法正常工作,当我更改fontFamily参数时,它给了我错误在Text对象中.

I have already created a folder assets/fonts and added the fonts in the folder also i created the FontManifest.json and put it in the assets folder but it the code is not working it gives me error when i change the fontFamily parameter in the Text object.

如何在Flutter for Web项目中使用字体?

how can i use the fonts to the Flutter for Web project?

推荐答案

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

Check if assets folder is located in web folder. Next, compare FontManifest.json content with the example below:

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

更新

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

Since the Flutter for web project is currently merged with the main Flutter repository, this method is no longer recommended. Created in web folder FontManifest.json file conflicts with created by compiler one. Specify fonts in the in the pubspec.yaml file.

这篇关于如何更改Flutter for Web Font?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆