D
Flutter CoreBeginner10 XP3 min read

Explain the structure of pubspec.yaml and key fields

TL;DR: pubspec.yaml is the Flutter/Dart project manifest defining package name, version, dependencies (pub.dev packages), dev_dependencies (build tools), flutter section (assets, fonts), and environment SDK constraints.

Full Answer

pubspec.yaml is read by the pub tool to resolve, fetch, and manage all project dependencies. It's the equivalent of package.json in Node.js.

  • name: required, package identifier on pub.dev
  • version: semver, format MAJOR.MINOR.PATCH+BUILD_NUMBER
  • environment.sdk: Dart SDK version constraint
  • dependencies: packages required at runtime
  • dev_dependencies: packages only needed during development/testing
  • flutter.assets: list of asset files/directories to bundle
  • flutter.fonts: custom font definitions with family name and weights

Code Examples

yamlTypical pubspec.yaml structure
Output
flutter pub get downloads and resolves all dependencies. Assets and fonts become available at runtime.

Interview Tip

💡

The version field's build number (+45) is what app stores use to distinguish uploads. The semver part (1.2.3) is shown to users. Automating build number increment in CI is a best practice.

#pubspec#dependencies#assets#fonts#versioning