Skip to content
pubscout

pubspec_extract

2.2.1, released 4 weeks ago by nfet.net

Extracts Dart pubspec.yaml file and generates pubspec.dart at build time

WASM-ready
$ flutter pub add pubspec_extract
Source repository

What it does

Extracts metadata and dependencies from pubspec.yaml and outputs a Dart file containing a class with these values. It can be run as a standalone command-line tool or integrated using build_runner.

AI-written summary of version 2.2.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to access app version, name, or description inside your Dart code
  • You want to automate reading pubspec configuration during compilation

Skip it when

  • You need dynamic runtime reading of external YAML assets without code generation

Strengths

  • Supports both command-line usage and build_runner integration
  • Highly configurable extraction of specific top-level keys

Weaknesses

  • Requires regeneration when pubspec.yaml changes if not using build_runner

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
7

Add pubspec_extract as a dev dependency and run via dart run or build_runner.

import 'pubspec.dart';

void main() {
  print(Pubspec.name);
  print(Pubspec.description);
  print(Pubspec.version);
}

Alternatives

Packages that do the same job and could replace pubspec_extract.

  • json_serializable

    Automatically generate code for converting Dart classes to and from JSON.

  • checked_yaml

    Provides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.

  • mason

    Dart template generator for quick file creation

  • envied

    Explicitly reads environment variables into a dart file from a .env file.

Works with

Packages commonly used together with pubspec_extract: ones it builds on, ones built on it, and its own family.