搜索插件、代码仓与 APP 分类

插件详情v2.2.1

build_version

一个用于将包版本提取到代码中的构建器。

AndroidiOSmacOSWindowsLinux
近 30 天下载
13.9万
喜欢数
33
Pub 分数
150

安装插件

flutter pub add build_version

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

build_version 是一个 Flutter/Dart 包,可在构建过程中生成包含当前包版本的 Dart 文件。它从 pubspec.yaml 提取版本信息,并将其作为常量提供给应用程序代码,从而在运行时无需手动更新即可访问版本详情。这对于调试、日志记录或在 UI 中显示版本号特别有用。该包与 build_runner 无缝集成,并支持 Android、iOS、macOS、Windows 和 Linux 等多个平台。

适合场景

  • 在设置中显示应用版本
  • 记录版本信息以用于调试
  • 自动化代码中的版本注入
  • 在构建中跟踪发布版本
  • 在应用逻辑中启用版本检查

主要特点

  • 自动生成版本常量
  • 从 pubspec.yaml 提取版本
  • 支持多个平台
  • 与 build_runner 集成
  • 所需配置最少

适合对象

  • 需要运行时版本访问权限的应用
  • 希望实现自动化版本管理的团队
  • 使用 build_runner 工作流的项目
  • 寻求最小样板代码的开发者
  • 需要版本元数据的 CI/CD 流水线

使用建议

  • 需要设置 build_runner
  • 版本在构建后为静态
  • 不适用于动态版本更改
  • 在版本更新时可能需要重新构建
  • 仅限 pubspec.yaml 中的 version 字段

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

CI Pub Package package publisher

Include the version of your package in our source code.

  1. Add build_version to pubspec.yaml. Also make sure there is a version field.

    name: my_pkg
    version: 1.2.3
    dev_dependencies:
      build_runner: ^1.0.0
      build_version: ^2.0.0
    
  2. Run a build.

    > dart run build_runner build
    

    lib/src/version.dart will be generated with content:

    // Generated code. Do not modify.
    const packageVersion = '1.2.3';
    

To change the path of the generated file, create a build.yaml in the root of your package. By changing the output option of this builder, the path can be customized:

targets:
  $default:
    builders:
      build_version:
        options:
          output: lib/src/custom/path/to/version.dart

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目