How to change Flutter for web Font?

你说的曾经没有我的故事 提交于 2019-12-07 21:38:25

问题


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

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"
        }
      ]
    }
  ]

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.

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


回答1:


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
      }
    ]
  }
]


来源:https://stackoverflow.com/questions/57023412/how-to-change-flutter-for-web-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!