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

Overview

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, command-line tool, or backend app.

Pub

Common use-cases

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

Usage

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

    dev_dependencies:
      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'
    authors:
      - Vince Varga <[email protected]>
    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: https://pub.dev/packages/build_pubspec
    const List<String> authors = [
      'Vince Varga <[email protected]>',
    ];
    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.

targets:
  $default:
    builders:
      build_pubspec:
        options:
          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:

targets:
  $default:
    builders:
      build_pubspec:
        options:
          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:

targets:
  $default:
    builders:
      build_pubspec:
        enabled: false
      build_pubspec|build_pubspec_part:
        enabled: true
        generate_for: ['lib/src/example.dart']
        options:
          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.

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.

TODOs

I just got rid of Travis, so I need to take care of a new CI/CD pipeline. GitHub Actions.

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

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

Nov 11, 2022

Package to get details of the Instagram user and download reels video.

Package to get details of the Instagram user and download reels video.

Flutter package to get Instagram user details and download reels videos. How to Use To use flutter_insta, first start by importing the package. import

Nov 12, 2022

Contactus - a flutter package. The most common functionality added in any commercial app is the Developer's contact details

Contactus - a flutter package. The most common functionality added in any commercial app is the Developer's contact details

Contact Us The most common functionality added in any commercial app is the Developer's contact details!! So this package helps the developers to simp

Aug 4, 2022

Responsive Scaffold - On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item. Maintainer: @rodydavis

Responsive Scaffold - On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item. Maintainer: @rodydavis

responsive_scaffold View the online demo here! On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item.

Dec 2, 2022

It's OK to love Flutter and hate hand-coding design elements. Parabeac-Core converts design files into Flutter code.

It's OK to love Flutter and hate hand-coding design elements. Parabeac-Core converts design files into Flutter code.

Parabeac-Core Parabeac-Core converts design files into Flutter code driven by open-source & community. Contribute · Discord Community · Designer Proto

Jan 4, 2023

Call Kit is a prebuilt feature-rich call component, which enables you to build one-on-one and group voice/video calls into your app with only a few lines of code.

Call Kit is a prebuilt feature-rich call component, which enables you to build one-on-one and group voice/video calls into your app with only a few lines of code.

Call Kit (ZegoUIKitPrebuiltCall) Call Kit is a prebuilt feature-rich call component, which enables you to build one-on-one and group voice/video calls

Dec 26, 2022

Flutter Application to purchase movie tickets, search for a movie, view movie details and proceed to select seats and movie times.

Flutter Application to purchase movie tickets, search for a movie, view movie details and proceed to select seats and movie times.

Flutter Application to purchase movie tickets, search for a movie, view movie details and proceed to select seats and movie times.

May 25, 2022

Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.

Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.

Dart_Native Dart_Native operates as both a code generator tool and a bridge to communicate between Dart and native APIs. Replaces the low-performing F

Jan 4, 2023

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

advance_image_picker Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edi

Dec 19, 2022
Owner
dartside.dev
Hacking on Flutter and Dart.
dartside.dev
Flutter ticket pass - A Flutter Widget to display the details of a ticket/pass purchased by customers and display the details of the purchase

ticket_pass_package A Flutter package to display the purchase of a ticket/pass along with additional details such as list of buyers. The source code i

null 40 Aug 13, 2022
A builder for extracting a package version into code

Include the version of your package in our source code. Add build_version to pubspec.yaml. Also make sure there is a version field. name: my_pkg versi

Kevin Moore 39 Dec 7, 2022
A pure Dart package for working with RDF (resource description framework).

RDFLib A pure Dart package for working with RDF (resource description framework). Features Create triple instances (with data types) Create a graph to

null 5 Dec 15, 2022
Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc.

ruqe Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc. Additionally, the librar

Alexander Nitiola 12 Dec 28, 2022
🌈 Repository for a compass project, basically an App for displaying bank transfers, with API requests, Flag persistence, Infinite Scroll, Error Handling, Unit Tests, Extract Sharing working with SOLID, BLoC and Designer Patterns.

?? Green Bank Aplicação desenvolvida em Flutter com intuito de trabalhar conexão com API, Gerenciamento de estado usando BLoC, Refatoração, Arquitetur

André Guerra Santos 28 Oct 7, 2022
Run Pubspec Script (RPS)

Run Pubspec Script (RPS) Define and use scripts from your pubspec.yaml file. Get

Kamil Klyta 12 Nov 27, 2022
Shader manages the compilation of your GLSL shaders into SPIR-V byte code and Dart code

shader Shader manages the compilation of your GLSL shaders into SPIR-V byte code and Dart code. Quickstart # Install cli dart pub global activate shad

Felix Blaschke 25 Dec 1, 2022
A flutter project with a description of the basic Flutter framework

Pengenalan kepada Mobile Platform (Slide) Apa itu Flutter Framework Pemasangan persekitaran Flutter, Android SDK & VSCode IDE Widget Layout & UI Eleme

Mohamad Zaki Mustafa 3 Jan 3, 2022
BreakingBad-App - A description of the Braking Bad series, using flutter bloc

breaking_bad The application is a description of the Braking Bad series Using Bl

Mohamed Hossam 0 Jan 9, 2022