简体   繁体   English

我想在flutter应用程序中添加字体,但pubspec.yaml中有问题

[英]i want to add fonts in flutter app, but there is a problem in pubspec.yaml

This is my pubspec.yaml Working dir: C:\\Users\\kom.13\\AndroidStudioProjects\\flutter_app1 C:\\src\\flutter\\flutter\\bin\\cache\\dart-sdk\\bin\\pub.bat get Error on line 22, column 2 of pubspec.yaml: Expected a key while parsing a block mapping.这是我的 pubspec.yaml 工作目录:C:\\Users\\kom.13\\AndroidStudioProjects\\flutter_app1 C:\\src\\flutter\\flutter\\bin\\cache\\dart-sdk\\bin\\pub.bat 在第 22 行列上获取错误pubspec.yaml 的 2:在解析块映射时需要一个键。 â•· 22 │ fonts: │ ^ ╵ Process finished with exit code 65 â• 22 â”字体:â” ^ ╵ 进程完成,退出代码为 65

name: flutter_app1
description: A new Flutter application.

publish_to:
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

 fonts:
  - family: Pacifico
  fonts:
  - asset: fonts/Pacifico-Regular.ttf

so, you have an indentation issue in the fonts sections.因此,您在字体部分存在缩进问题。 Do this instead:改为这样做:

name: flutter_app1
description: A new Flutter application.

publish_to:
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

 fonts:
   - family: Pacifico
     fonts:
       - asset: fonts/Pacifico-Regular.ttf

For reference, check this page: https://flutter.dev/docs/cookbook/design/fonts作为参考,请查看此页面: https : //flutter.dev/docs/cookbook/design/fonts

I think You have an Error of indentation of which means your fonts are not at the correct position, see mine below code.我认为您有一个缩进错误,这意味着您的字体不在正确的位置,请参阅下面的代码。

fonts:
    - family: GraphikWide
      fonts:
        - asset: fonts/Graphik-Wide-Regular.otf
        - asset: fonts/Graphik-Wide-Medium.otf
          weight: 400
    - family: Gibson
      fonts:
        - asset: fonts/gibson-regular.ttf
        - asset: fonts/gibson-semibold.ttf
          weight: 400
        - asset: fonts/gibson-light.ttf
          weight: 100
  

just replace your full font code in pubspec with my code then do the changes只需用我的代码替换 pubspec 中的完整字体代码,然后进行更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将sqflite添加到pubspec.yaml时,为什么我的flutter应用程序会崩溃? - Why does my flutter app crash when I add `sqflite` to my pubspec.yaml? 地理位置错误:如果我添加pubspec.yaml文件,则无法建立^ 3.0.0,无法构建android应用 - Getting Error With geolocator: ^3.0.0 in flutter if i add in pubspec.yaml file, not able to build android app 在flutter中,如何将tfl​​ite添加为pubspec.yaml文件中的依赖项? - In flutter, How to add tflite as a dependency in pubspec.yaml ?file? 当我添加到 pubspec.yaml 时 firebase auth 出现问题 - problem with firebase auth when i added to pubspec.yaml Flutter pubspec.yaml Android版本代码 - Flutter pubspec.yaml Android versionCode flutter pubspec.yaml 退出代码 65 - flutter pubspec.yaml exit code 65 flutter 中的 APK 或 Android App Bundle 的版本代码没有改变。即使从 pubspec.yaml 更改它之后 - version code not changing of APK or Android App Bundle in the flutter. Even after changing it from pubspec.yaml 如何修复“错误:找不到 pubspec.yaml 文件”。 在 flutter 和 Android 工作室? - How do I fix "Error: No pubspec.yaml file found." in flutter w/ Android studio? 在 pubspec.yaml 中使用 fluttertoast 时 flutter 构建问题 - flutter build issue when use fluttertoast in pubspec.yaml 在“pubspec.yaml”中找不到“flutter.plugin.platforms”键 - Cannot find the `flutter.plugin.platforms` key in the `pubspec.yaml`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM