built_version 1.1.0 copy "built_version: ^1.1.0" to clipboard
built_version: ^1.1.0 copied to clipboard

Generate source code with the package's version by annotating a getter.

built_version #

Provides Dart build systems for generating a package version string accessible at compile time.

The builder generates code when it finds members annotated with classes defined in package:built_version_annotation.

Setup #

Example #

Given a library example.dart with a getter annotated with BuiltVersion:

import 'package:built_version_annotation/built_version_annotation.dart';

part 'example.g.dart';

@BuiltVersion()
String get version => _$PackageVersion;

Building creates the corresponding example.g.dart:

part of 'example.dart';

String get _$PackageVersion => '1.0.0';

The value of _$PackageVersion will be the value found in the project's pubspec.yaml.

Running the code generator #

Once you have added the annotations to your code you then need to run the code generator to generate the missing .g.dart generated dart files.

Run > dart run build_runner build in the package directory.

Annotations #

The only annotation is [BuiltVersion](). When applied to a getter, a _$PackageVersion code will be generated when you build.

Motivation #

Why package:built_version vs. package:package_info_plus? This package offers a build-time value that is accessible in Dart code that is generated from the version code in pubspec.yaml. This value is available for a single plugin/package, as opposed to package_info_plus which takes the value from the current running application.

0
likes
130
points
66
downloads

Publisher

verified publishersamueljhuff.com

Weekly Downloads

Generate source code with the package's version by annotating a getter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, build, built_version_annotation, glob, meta, pub_semver, source_gen

More

Packages that depend on built_version