代码之家  ›  专栏  ›  技术社区  ›  Farhana Naaz Ansari Jay Dwivedi

颤振:自定义字体不显示效果

  •  2
  • Farhana Naaz Ansari Jay Dwivedi  · 技术社区  · 7 年前

    我尝试了很多解决方案,但是没有一个有效,我尝试了这些解决方案 here , here 但字体仍然没有显示任何效果,应用程序也没有显示任何错误。 代码有什么问题。

    这是我下面的代码

      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 回复  |  直到 7 年前
        1
  •  1
  •   Jordan Davies    7 年前

    我认为这和你的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
    
        2
  •  0
  •   johrpan    7 年前

    你给你的字体家族命名了 Raleway 但是用了绳子 Raleway-Regular 在您的代码中。把它们中的一个换成另一个就可以了。

        3
  •  0
  •   Alex Jone    7 年前

    实际上,我在应用程序中也使用了这种精确的字体。我想你需要买一个许可证,但我记不清了。总之,您的字体名称如下:

    fonts:
        family: Raleway
    

    在这里,您命名了字体 巷道 ,因此在颤振代码中,必须指定 准确的 同名:

    fontFamily: 'Raleway'