build_pubspec 0.2.0 icon indicating copy to clipboard operation
build_pubspec: ^0.2.0 copied to clipboard


Extract pubspec details (such as package version, author and description) into Dart code.

build_pubspec #

This package helps you convert fields from your pubspec.yaml file into Dart code. Based on the fields in your pubspec, this package will generate Dart code so that you can access these fields easily from your Flutter, AngularDart, or backend app.


Common use-cases #

  • Display current version of your app to your users in your mobile app
  • Add build information to your logs, analytics or backend calls
  • Create command-line apps and fill out the help and version commands automatically
  • Create example apps for your Flutter packages and plugins with an up-to-date description and links to your docs, issue tracker and repository

Do you have another use case for this package? Tell me about it on Twitter or open a issue on GitHub. I appreciate your help in making this package better.

Usage #

  1. Add build_pubspec to your pubspec.yaml as dev_dependency. Make sure build_runner is also listed as development dependency.

      build_runner: ^1.0.0
      build_pubspec: ^1.0.0
  2. Get dependencies: pub get. If you are using Flutter, run flutter pub get.

  3. Build!

    $ pub run build_runner build

    Based on the following pubspec.yaml file...

    name: build_pubspec_example
    description: This is an example description.
    publish_to: 'none'
      - Vince Varga <>
    version: 0.1.2

    ... the default build will create the lib/src/pubspec.dart file:

    // Generated file. Do not modify.
    // This file is generated using the build_pubspec package.
    // For more information, go to:
    const List<String> authors = [
      'Vince Varga <>',
    const String description =
        '''This is an example description.''';
    const String name = '''build_pubspec_example''';
    const String version = '''0.1.2''';
  4. Use the generated Dart code.

    You can now include this Dart file in your app code if you want to reference a field from your pubspec.yaml file.

Examples #

I maintain various examples for this package. Check them all out in the examples/ folder.

Customize your build #

Create a build.yaml file in your project.

Change field names #

You can customize the output Dart file's fields names, for example, if you want to output the version as const String v = '...';'.

If a key is not present in the pubspec.yaml, it will not be part of the output Dart file.

If you wish to skip a key, set its field name option to empty string.

              authors_field_name: betterAuthors
              description_field_name: betterDescription
              documentation_field_name: betterDocumentation
              homepage_field_name: betterHomepage
              issue_tracker_field_name: betterIssueTracker
              # name field is intentionally left empty in this example to
              # demo how to skip the name in the output dart file.
              name_field_name: ''
              repository_field_name: betterRepository
              version_field_name: betterVersion

Change output file #

By default, the destination file is lib/src/pubspec.dart.

If you wish to change it, create a build.yaml file in your project:

          destination_file: 'lib/details.dart'

Part files with source_gen #

It is also possible to generate the version string as a part of an existing library in your package.

Disable the default builder, and enable the part builder:

        enabled: false
        enabled: true
        generate_for: ['lib/src/example.dart']
          version_field_name: 'exampleVersion' # defaults to 'packageVersion'

Make sure your lib/src/example.dart contains part 'example.version.g.dart';,

Once you run pub run build_runner build, the part file will be generated into lib/src/my_lib.version.g.dart.



  • analyze, lint, run tests, all the usual stuff
  • go to example folders and make sure the examples run correctly, make sure no git changes

Acknowledgements #

This package is based on build_version. Thank you for the original author, Kevin Moore. It also includes fixes to the original repository from Alexey Knyazev. I could not have created this package without their original work.

pub points


verified publisher

Extract pubspec details (such as package version, author and description) into Dart code.

Repository (GitHub)
View/report issues


Icon for licenses.unknown (LICENSE)


build, build_config, meta, pubspec_parse, source_gen


Packages that depend on build_pubspec