flutter pub get 的時候:A dependency specification must be a string or a mapping.

ayubene發表於2024-07-13

想在pubspec.yaml 檔案中新增字型:報錯了

  fonts:
    - family: MiaoZi
      fonts:
        - asset: assets/fonts/MiaoZi-YunYingTi-2.ttf
          weight: 500

看了這篇文章解決了

我原來是加在

dependencies:
  flutter:
    sdk: flutter
  # 新新增的依賴
  fonts:
    - family: MiaoZi
      fonts:
        - asset: assets/fonts/MiaoZi-YunYingTi-2.ttf
          weight: 500

其實應該加在最後

name: flutter01
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.4.3 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  english_words: ^4.0.0
  cupertino_icons: ^1.0.6

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  fonts:
    - family: MiaoZi
      fonts:
        - asset: assets/fonts/MiaoZi-YunYingTi-2.ttf
          weight: 500


相關文章