dart_define
2.1.2, released a year ago by mankeli.co
Utility for generating and populating dart-define configuration files
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.
76Compare - mime
Utilities to resolve MIME types from file names, magic bytes, and to parse multipart streams.
92Compare - io
Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
88Compare - flutter_flavorizr
A utility to easily create and configure application flavors in Flutter.
86Compare
Works with
Packages commonly used together with dart_define: ones it builds on, ones built on it, and its own family.
- yamldart_define depends on itA Dart library for parsing YAML documents into Dart data structures.
- json_annotationdart_define depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- argsdart_define depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- mustache_templatedart_define depends on itA Dart library that parses and renders Mustache templates.
- checked_yamldart_define depends on itProvides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.
- freezed_annotationdart_define depends on itAnnotations for the freezed code-generator.
- pub_updaterdart_define depends on itChecks if a pub package is up to date and can trigger updates
- cli_completiondart_define depends on itCompletion functionality for Dart Command-Line Interfaces built using CommandRunner.