颤动:自定义字体不起作用

时间:2019-01-11 14:20:11

标签: android fonts dart flutter

我在SO上尝试了许多解决方案,但没有一个起作用,我尝试了herehere这些解决方案,但字体仍然没有效果,并且应用程序未显示任何错误。 代码有什么问题。

这是我的下面的代码

  Widget textSection = new Container(
  decoration: new BoxDecoration(
      color: Colors.blue[100], border: new Border.all(color: Colors.black)),
  padding: const EdgeInsets.all(18.0),
  margin: const EdgeInsets.only(left: 14.0, right: 14.0, bottom: 14.0),
  width: double.infinity,
  child: new Text(
    "Labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
    textAlign: TextAlign.center,
    style: new TextStyle(
        color: Colors.black45,
        fontSize: 22.0,
        fontFamily: 'Raleway-Regular'),
    softWrap: true,
  ),
);

This is My yaml file

this is my project hierarchy

3 个答案:

答案 0 :(得分:1)

我认为这与您的pubspec文件有关,缩进很重要。

flutter:
  uses-material-design: true
  assets: 
    - image/lake.png
  fonts:
    - family: Raleway
      fonts:
        - asset: fonts/Raleway-Regular.ttf
        - asset: fonts/Raleway-Italic.ttf
          style: italic

答案 1 :(得分:0)

您将字体家族命名为Raleway,但在代码中使用了字符串Raleway-Regular。将其中一个更改为另一个,它应该可以工作。

答案 2 :(得分:0)

我实际上也在我的应用程序中使用了这种确切的字体。我认为您需要为此购买许可证,但是我不确定。无论如何,您的字体名称在这里:

fonts:
    family: Raleway

在这里,您将字体命名为 Raleway ,因此在Flutter代码中,必须指定 exact 相同的名称:

fontFamily: 'Raleway'

相关问题