Skip to content
pubscout

dart_define

2.1.2, released a year ago by mankeli.co

Utility for generating and populating dart-define configuration files

WASM-ready
$ flutter pub add dart_define
Source repository

What it does

Generates Dart code and JSON configuration files for compile-time variables and flavors using pubspec.yaml configurations and environment variables.

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

Use it when

  • You need a structured way to handle secrets and compile-time variables across local development and CI/CD pipelines.
  • You want to generate Dart configuration classes and JSON files for Flutter's --dart-define-from-file option.

Skip it when

  • You prefer managing your environment variables and launch arguments manually.
  • You are not using compile-time variables or flavors in your Flutter application.

Strengths

  • Integrates smoothly with CI/CD pipelines by reading from system environment variables.
  • Validates required configuration variables to prevent missing value runtime errors.
  • Supports multiple flavors and custom output paths.

Weaknesses

  • Requires CLI tool activation or adding as a dev dependency.
  • Must be careful with caching in CI/CD environments requiring the --force flag.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
11

Activate the CLI tool globally or add as a dev dependency, then define variables in pubspec.yaml.

class DartDefine {
    static const stringValue = String.fromEnvironment('STRING_VALUE');
    static const intValue = int.fromEnvironment('INT_VALUE');
    static const boolValue = bool.fromEnvironment('BOOL_VALUE');
}

Alternatives

Packages that do the same job and could replace dart_define.

  • gtk

    GTK utilities for Flutter Linux applications, providing settings and application lifecycle helpers.

  • mime

    Utilities to resolve MIME types from file names, magic bytes, and to parse multipart streams.

  • io

    Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.

  • flutter_flavorizr

    A utility to easily create and configure application flavors in Flutter.

Works with

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