Search code examples
flutterdartyamlmaterial-designpubspec

"uses-material-design: true" not working with other assets in pubspec.yaml


I cannot add any assets like images, fonts, etc. to my project app until I delete/comment this line

uses-material-design: true

The error

Error detected in pubspec.yaml:
Restarted application in ٨ms.
Error on line 25, column 4: Expected a key while parsing a block mapping.
   ╷
25 │    assets:
   │    ^
   ╵
Exception: Please correct the pubspec.yaml file at .\pubspec.yaml

Except for this problem, everything is okay in pubspec.yaml

name: mi_card
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
   assets:
    - images/

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

     - family: Source Sans Pro
       fonts:
        - asset: fonts/SourceSansPro-Regular.ttf

but because I need to use material icons, I need to add it with my assets, so How to solve this issue?


Solution

  • pubspec.yaml is sensitive to indentation.

    and your in file after uses-material-design: true is indented by one space , try to remove it and it will work.

    copy this and try :

    name: mi_card
    description: A new Flutter application.
    
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.1.0 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
    
      cupertino_icons: ^0.1.2
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    
    flutter:
    
      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true
    
        # To add assets to your application, add an assets section, like this:
      assets:
        - images/
    
      fonts:
        - family: Pacifico
          fonts:
            - asset: fonts/Pacifico-Regular.ttf
    
        - family: Source Sans Pro
          fonts:
            - asset: fonts/SourceSansPro-Regular.ttf