Sendi Nur Cahya
Sendi Nur Cahya

Reputation: 11

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. ╷ 22 │ fonts: │ ^ ╵ Process finished with exit code 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

Upvotes: 1

Views: 2818

Answers (2)

Didier Prophete
Didier Prophete

Reputation: 2031

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

Upvotes: 2

Atul Chaudhary
Atul Chaudhary

Reputation: 1779

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

Upvotes: 0

Related Questions