{"id":15293092,"url":"https://github.com/tatsuukraine/dart_environment_config","last_synced_at":"2026-03-11T22:45:09.602Z","repository":{"id":39751194,"uuid":"242590948","full_name":"TatsuUkraine/dart_environment_config","owner":"TatsuUkraine","description":"Environment specific config generator for Dart and Flutter applications during CI/CD builds","archived":false,"fork":false,"pushed_at":"2025-03-08T22:01:36.000Z","size":95,"stargazers_count":92,"open_issues_count":7,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T01:07:57.604Z","etag":null,"topics":["ci-cd","configuration","dart","dotenv","environment","environment-configuration","environment-variables","flutter"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/environment_config","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TatsuUkraine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-23T21:07:41.000Z","updated_at":"2025-03-08T22:01:24.000Z","dependencies_parsed_at":"2025-02-12T14:10:14.731Z","dependency_job_id":"e31da9f9-7fe0-4882-9768-8c520bc51a7d","html_url":"https://github.com/TatsuUkraine/dart_environment_config","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TatsuUkraine%2Fdart_environment_config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TatsuUkraine%2Fdart_environment_config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TatsuUkraine%2Fdart_environment_config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TatsuUkraine%2Fdart_environment_config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TatsuUkraine","download_url":"https://codeload.github.com/TatsuUkraine/dart_environment_config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","configuration","dart","dotenv","environment","environment-configuration","environment-variables","flutter"],"created_at":"2024-09-30T16:39:46.706Z","updated_at":"2026-03-11T22:45:09.572Z","avatar_url":"https://github.com/TatsuUkraine.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Environment Config Generator\n\n[![pub package](https://img.shields.io/pub/v/environment_config.svg)](https://pub.dartlang.org/packages/environment_config)\n\nEnvironment specific config generator.\n\nAllows to specify env configuration during CI/CD build.\n\nPrimarily created to simplify Flutter build configuration.\n\n## Features\n\n- flexible configuration for Config class generation\n- allows to specify pattern for field values\n- allows to define required and optional keys for generation\n- allows to export variables to `.env` file\n\n## Note for Flutter developers\n\nThis package still will be maintained, but if you are using Flutter\nversion 1.17 and higher, consider using compile-time variables to\nconfigure your environments instead of this package. More about\ncompile-time variables you can read\n[here](https://medium.com/@tatsu.ukraine/flutter-1-17-no-more-flavors-no-more-ios-schemas-command-argument-that-solves-everything-8b145ed4285d)\n\n## Migration from 1.x.x to 2.x.x\n\nIn `1.x.x` path for `.env` was generated against `lib/` folder. Starting\nfrom `2.x.x` path for `.env` file is generated against your root app\nfolder.\n\nSo by default `.env` file will be generated alongside with\n`pubspec.yaml` and other root files.\n\n## Table of contents\n\n- [Getting Started](#getting-started)\n- [Configuration](#config)\n  - [Command options](#command-options)\n  - [Class configuration](#class-configuration)\n    - [Class configuration examples](#config-examples)\n  - [Field configuration](#field-configuration)\n    - [Fields config examples](#fields-config-examples)\n      - [Pattern example](#pattern-example)\n      - [DotEnv example](#dotenv-example)\n      - [Global environment variable example](#global-environment-variable-example)\n  - [Extensions](#extensions)\n    - [Basic Extension config usage](#basic-extension-config-usage)\n    - [Development Extension example](#development-extension-example)\n- [Integration with CI/CD](#integration-with-cicd)\n- [Integration with other packages](#integration-with-other-packages)\n\n## Getting Started\n\nInstall package as dependency. Or use global active\n\n`dart pub global activate environment_config`\n\nCreate `environment_config.yaml` or update `package.yaml` file with following code\n\n**Note** This is an example with ALL possible params\n\n```yaml\nenvironment_config:\n  path: environment_config.dart # optional, result file path against `lib/` folder\n  dotenv_path: .env # optional, result file path for .env file against project root folder\n  class: EnvironmentConfig # optional, class name\n  dev_extension: # optional, by default undefined, allows to specify command option to use extension\n  \n  fields: # set of fields for command\n    some_key: # key name\n      type: # optional, default to 'String'\n      short_name: # optional, short name for key during command run\n      const: # optional, default to TRUE\n      pattern: # optional, specified pattern for key value, use __VALUE__ to insert entered value anywhere in the pattern\n      default: # optional, default value for key, if not provided key will be required during command run\n      dotenv: # optional, default to FALSE, if this field should be added to .env file\n      config_field: # optional, default to TRUE, if this field should be added to Dart file\n      env_var: # optional, global environment variable name\n      static: # options, default to TRUE, if this field should be static, if FALSE, `const` will be be ignored\n      \n  imports: # optional, array of imports, to include in config file\n    - package:some_package\n      \n  extensions: # set of extensions for default field list\n    some_extension: # extension name\n      some_key:\n        const: # optional, overrides `const` value for the field\n        pattern: # optional, overrides `pattern` value for the field\n        default: # optional, overrides `default` value for the field\n        env_var: # optional, overrides `env_var` value for the field\n        \n    imports: # optional, adds set of imports to main configulration\n      - package:some_other_package\n      \n```\n\nRun `pub get` to install dependencies. (if you installed it as deps in you project)\n\nAfter config is specified in YAML file run following command\n\n```\npub run environment_config:generate --some_key=some_value\n```\nOr for flutter project\n\n```\nflutter pub run environment_config:generate --some_key=some_value\n```\n\nOr just next command if you installed package globally\n\n```\nenvironment-config-generate --some_key=some_value\n```\n\nThis command with generate file, that was specified in `path` key with\nclass, fields and name specified in yaml config.\n\nImport this file into your application and use it.\n\n**Note:** It's recommended to add generated config files to `.gitignore`\n\n## Why this package is needed?\n\nThis package allows to integrate config generation based on environment\nin an easy way.\n\nUnlike most env specific configurations this package can be added to\nCI/CD build process to generate config file with values, that specific to\nparticular env, without need to specify your Prod credentials\nanywhere except your build process.\n\nAlso reading this values doesn't require async process, that will decrease\nyou app start time\n\nObviously this package doesn't obfuscate or encrypt config values, but\ngenerated Dart file will be build and obfuscated with rest of\nyour mobile application code. If you want to secure your sensitive\ninformation you can use encrypted values and **pattern** key to wrap it\nwith your decrypt library. But overall keep in mind that there is no way\nto fully [secure your app from reverse engineering](https://rammic.github.io/2015/07/28/hiding-secrets-in-android-apps/)\n\nAlso this package allows to generate `.env` file with same key value pairs\n\n## Config\n\n## Command options\n\nDuring command run YAML file will be parsed to define keys for command.\n\n- `config` - path to custom yaml file with package configuration\n- `config_extension` - name of the extension, that should be used for\n  config generation\n- any key name, that specified in yaml file under `fields` key\n- `dev_extension` key name, allows to use this key as bool flag\n\nFor example. If you have next yaml config\n\n```yaml\nenvironment_config:\n  fields:\n    key_one:\n      short_name: o #optional\n    key_two:\n      short_name: t #optional\n```\n\nYou will be able tou run command with following options\n```\nflutter pub run environment_config:generate --key_one=something --key_two=other\n```\n\nOr (if `short_name` is specified)\n```\nflutter pub run environment_config:generate -o something -t other\n```\n\nBoth commands will generate same dart class\n\n```dart\nclass EnvironmentConfig {\n  static const String key_one = 'something';\n\n  static const String key_two = 'other';\n}\n```\n\n### Multiple config files\n\nIf you want to use different config YAML files for different environment\nor you need to generate multiple configurations, use `config` key during\ncommand run\n\n```\nflutter pub run environment_config:generate --config=path/to/file.yaml\n```\n\n## Class configuration\n\nClass and file can be configured with next options\n\n- `path` - path to file against `lib` folder, by default it's `environment_config.dart`\n- `dotenv_path` - path to file against root app folder, by default it's\n  `.env`\n- `class` - class name, by default will be generated based on file name\n- `const` - optional, defines if class constructor should be\ndefined as `const`.\n- `imports` - array of imports to add to generated config file\n- `fields`- set of fields, that should be defined in configuration files\n- `dev_extension` - defines which extension should be treated as dev\n  extension, if specified - it's value can be used during command run as\n  bool flag\n- `extensions` - set of configurations, that can extend default config\n\nIf `class` is not specified value for class name will be generate based\non file name in `path` field. It will convert `snake_case` into\n`CamelCase`.\n\nField `dotenv_path` will be used only if at least one field contains `dotenv: true`\n\n### Config Examples\n\n#### Custom path example\n\n```yaml\nenvironment_config:\n  path: config/some_config.dart\n  \n  ...\n```\nWill create file with name `some_config.dart` in `lib/config` folder\nwith following class\n\n```dart\nclass SomeConfig {\n  ///\n}\n```\n\n#### Custom class name example\n```yaml\nenvironment_config:\n  path: config/some_other_config_file.dart\n  class: OtherClass\n  \n  ...\n```\nwill create file with name `some_other_config_file.dart` in `lib/config`\nfolder with following class\n\n```dart\nclass OtherClass {\n  ///\n}\n```\n\n#### Class with const constructor\n\n```yaml\nenvironment_config:\n  class: OtherClass\n  const: true\n  \n  ...\n```\nwill create config with following class\n\n```dart\nclass OtherClass {\n  const OtherClass();\n  ///\n}\n```\n\nIf `const` is used it will force class to have const constructor or without it.\n\n## Field configuration\n\nTo define fields for config definition, provide key set under `fields` key.\n\nConfiguration accepts any amount of field keys. At least one field\nshould be specified\n\n**Note:** `config` key can't be used for field definition. It's reserved\nby command itself to define path to custom config yaml file\n\n**Note** If `dev_extension` is defined, its value can't be used as field\nname\n\nEach field accepts next params, each param is **optional**\n- `type` - field type, default to `String`\n- `const` - if field should be `const`, default to `TRUE`. If `FALSE`, `final` modifier will be used instead\n- `static` - if field should be `static`, default to `TRUE`. If `FALSE`,\n  `const` option will be ignored\n- `pattern` - pattern for field value. Inside value for this field\n  `__VALUE__` can be used. It will be replaced with actual entered value\n  or with default value\n- `default` - default value for the field. If not specified, field will be treated as required\n- `short_name` - short key name, that can be used during command run\ninstead of full field name. Accepts 1 symbol values only\n- `dotenv` - bool flag, if `TRUE` this field will be added to `.env` file.\n- `env_var` - environment global variable name\n- `config_field` - default to `TRUE`, indicates if this field should be\n  defined in Dart class config\n\n**If you want to generate `.env` file in addition to class config, at least ONE\nkey should have `dotenv` to be TRUE. Otherwise `.env` file won't be generated**\n\n**If field contains `dotenv: false` (which is default state) and\n`config_field: false` field will be ignored**\n\n**Note** If field config doesn't have `default` key specified it will be\ntreated as **required**. Which means that you need provide value for\nyour field in one of the following way:\n- argument during command run\n- global env variable, if `env_var` is specified\n\n**Note:** If `pattern` key is specified and `const` is `TRUE` ensure your\npattern also contains `const` modifier like this\n\n```yaml\nenvironment_config:\n  fields:\n    some_key:\n      pattern: const CustomClass('__VALUE__')\n```\n\n### Fields config examples\n\n#### Pattern example\n\n```yaml\nenvironment_config:\n  fields:\n    numberValue:\n      type: num\n      const: false\n      short_name: o #optional\n    customClassValue:\n      type: CustomClass\n      pattern: const CustomClass('__VALUE__')\n```\n\nThis config allows to run next command\n\n```\nflutter pub run environment_config:generate -o 345 --customClassValue=something\n```\n\nIt will generate following class\n\n```dart\nclass EnvironmentConfig {\n  static final num numberValue = 345;\n\n  static const CustomClass customClassValue = const CustomClass('something');\n}\n\n```\n\n#### DotEnv example\n\nTo create `.env` at least one key should have `dotenv: true` attribute\n```yaml\nenvironment_config:\n  fields:\n    first_key: # define field only in Dart class\n      type: num\n    second_key:\n      dotenv: true # will define field in Dart and in `.env`\n    third_key:\n      dotenv: true # will define field in `.env`\n      config_field: false # will exclude field from Dart config file\n```\n\n**Note** If `dotenv: false` and `config_field: false` this field won't\nbe added to `.env` and Dart config class\n\nThis command\n```\nflutter pub run environment_config:generate --first_key=123 --second_key=456 --third_key=789\n```\n\nwill generate Dart class config in `lib/` folder\n\n```dart\nclass EnvironmentConfig {\n  const EnvironmentConfig();\n\n  static const num first_key = 123;\n\n  static const String second_key = '456';\n}\n```\n\nand following `.env` in your root app folder\n\n```\nsecond_key=456\nthird_key=789\n```\n\n#### Global environment variable example\n\nIf you want to use value from environment variable, just define key\n`env_var`.\n\n```yaml\nenvironment_config:\n  fields:\n    first_key:\n      env_var: PATH\n```\n\nIn that way generator will try to get value from `PATH` global variable\nfor your key.\n\nGenerator will use next priority:\n- value from command arguments\n- value from environment variable `PATH`\n- value from [Extensions](#extensions) `default` key (if extension was\n  used that has `default` key)\n- value from `default` key (if it was specified)\n\n## Extensions\n\nExtensions allows you to define set of override rules for fields and\nimports.\n\nPrimarily extensions are needed to override main configuration and\nprovide some specific settings for environment like dev. That is why it\nallows to override just specific set of configuration keys for specific\nfield:\n- const\n- pattern\n- default\n- env_var\n\nExtension won't override other field keys to keep config class signature\nconsistent (if you need to add other keys in this list, feel free to\nopen an issue for that).\n\nAlso extension allows you to define import list in addition to default\nconfig. If extension is used - import list will be merged from default\nconfig and extension config\n\n### Basic Extension config usage\n\nTo use extension define it in config:\n\n```yaml\nenvironment_config:\n  fields:\n    first_key:\n    \n  imports:\n    - some:package\n      \n  extensions:\n    dev: # your extension name\n      fields:\n        first_key:\n          default: some value\n      \n      imports:\n        - other:package\n```\n\nThen if you run command like this\n\n```\nflutter pub run environment_config:generate\n```\n\nIt will throw an error that `first_key` is required. But you use\nextension\n\n```\nflutter pub run environment_config:generate --config-extension=dev\n```\n\nIt will generate following config class\n\n```dart\nimport 'some:package';\nimport 'other:package';\n\nclass EnvironmentConfig {\n  static const String first_key = 'some value';\n}\n```\n\n### Development Extension example\n\n**Note** Don't use development extension in your automated build tools.\nThere is a plan add verbose command run support eventually.\n\nMost common case when extension can be used is for your Dev environment.\nIn that way your default config will ensure that all fields are provided\nby build tool, and in same time - to generate config for dev\nenvironment, you won't need to define values for your fields.\n\nTo enable dev extension just add `dev_extension`\n\n```diff\nenvironment_config:\n  dev_extension: dev # `dev` here is the name of you extension\n  fields:\n    first_key:\n    \n  imports:\n    - some:package\n      \n  extensions:\n    dev:\n      fields:\n        first_key:\n          default: some value\n      \n      imports:\n        - other:package\n```\n\nThen you can run command like this, where `dev` is key name from\n`dev_extension`\n\n```\nflutter pub run environment_config:generate --dev\n```\n\n## Integration with CI/CD\n\nTo add config generation into any CI/CD, add command execution after\ndeps are installed and before build run.\n\n```\nflutter pub run environment_config:generate --\u003ckey_name\u003e=\u003ckey_value\u003e\n```\n\nIf your build tool allows to specify environment variables (for example\nlike Code Magic does), you can specify all needed key/values there. And\nin YAML config just define `env_var` in keys, where you want to use them\nwith same variable name like in your build tool. If all keys has\n`env_var` specified and your build tool also provides all needed values,\nyou can run generator just like this.\n\n```\nflutter pub run environment_config:generate\n```\n\n## Integration with other packages\n\n**Note** Next package was selected just for an example. You can choose any other package\nthat works with `.env` file\n\nSupport of `.env` generation was primarily added to generate config for\npackages that relies on it.\n\nFor example `.env` generation feature can be used with [flutter_config](https://pub.dev/packages/flutter_config)\npackage. This particular package allows you to pass environment variables from `.env`\ninto your native layer like your plugins or Android/iOS app configuration.\n\nFor more info see this docs for [Android](https://github.com/ByneappLLC/flutter_config/blob/master/doc/ANDROID.md)\nor [iOS](https://github.com/ByneappLLC/flutter_config/blob/master/doc/IOS.md)\n\n## Changelog\n\nPlease see the [Changelog](https://github.com/TatsuUkraine/dart_environment_config/blob/master/CHANGELOG.md)\npage to know what's recently changed.\n\n## Bugs/Requests\n\nIf you encounter any problems feel free to open an [issue](https://github.com/TatsuUkraine/dart_environment_config/issues).\nIf you feel the library is missing a feature,\nplease raise a ticket on Github and I'll look into it.\nPull request are also welcome.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatsuukraine%2Fdart_environment_config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftatsuukraine%2Fdart_environment_config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatsuukraine%2Fdart_environment_config/lists"}