dart中使用具有设定大小的自定义字体

dart中使用具有设定大小的自定义字体

本文介绍了如何在flutter/dart中使用具有设定大小的自定义字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 color fontWeight fontFamily style:style.copyWith 一起使用,我要使用的自定义字体是 Vonique ,我已经将其导入 pubspec.yaml

I'm trying to use color, fontWeight and fontFamily with style: style.copyWith, the custom font I'm trying to use is Vonique, I've imported it like so into pubspec.yaml

fonts:
       - family: Vonique
         fonts:
           - assets: fonts/Vonique-64-Bold-Italic.ttf
           - assets: fonts/Vonique-64-Italic.ttf
           - assets: fonts/Vonique-64-Bold.ttf
           - assets: fonts/Vonique-64.ttf

这是导入它的正确方法吗?

Is this the correct way to import it?

我尝试过同时使用"和不使用",但仍然不会更改文本字体.

I've tried it both was with '' and without '', still doesn't change the text font.

Text('Login',
 style: style.copyWith(
   color: Colors.redAccent, fontWeight: FontWeight.bold, fontFamily: 'Vonique'
),
),

Text('Login',
 style: style.copyWith(
   color: Colors.redAccent, fontWeight: FontWeight.bold, fontFamily: Vonique
),
),

我希望字体看起来像这里的字体 https://www.dafont.com/vonique-64.font ,但看起来不像那个.

I want the font to look like the one here https://www.dafont.com/vonique-64.font but it's not looking like that one.

推荐答案

如果要将字体应用于文本,则不要使用copyWith.只需使用新的TextStyle设置样式即可.

If you want to apply font to a text you don't use the copyWith. Just set your style using a new TextStyle.

Text('Login', style: TextStyle(fontFamily: 'Vonique',  fontWeight: FontWeight.bold))

如果要全局应用文本,则可以在材质应用中通过创建当前主题的副本并应用一些新属性(如以下内容)来应用全局文本更改.

If you want to apply text globally then in your material app you can apply global text changes by creating a copy of the current theme and applying some new properties like below.

MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
     // Uncomment in phase 3 to apply white to text
    textTheme: Theme.of(context).textTheme.apply(
      bodyColor: Colors.white,
      displayColor: Colors.white
    ),
  ),
  home: HomeSingleFile(),
);

要注意的是,如果您要使用现有样式并进行一些其他更改,请使用.apply方法而不是copyWith.

On the same note if you have an existing style that you want to apply with some additional changes use the .apply method instead of copyWith.

这篇关于如何在flutter/dart中使用具有设定大小的自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 05:19