{"id":15293145,"url":"https://github.com/alexey-nobody/flutter-app-environment","last_synced_at":"2026-01-11T13:34:37.807Z","repository":{"id":93858187,"uuid":"604651230","full_name":"alexey-nobody/flutter-app-environment","owner":"alexey-nobody","description":"Simple solution to handle environment variables using `.json` or config in entrypoint file.","archived":false,"fork":false,"pushed_at":"2025-01-31T07:56:28.000Z","size":65,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T03:34:43.305Z","etag":null,"topics":["dart","dartlang","flutter","flutter-package","flutter-plugin"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/flutter_app_environment","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexey-nobody.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":"2023-02-21T14:08:08.000Z","updated_at":"2025-01-31T07:56:04.000Z","dependencies_parsed_at":"2025-01-31T08:26:36.213Z","dependency_job_id":"cf63dec9-6a70-4e11-abfc-5e7d11ba2c3e","html_url":"https://github.com/alexey-nobody/flutter-app-environment","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"41f3d677b50f17df6a63eee2e4810831df75f023"},"previous_names":["alexey-nobody/flutter-app-environment","alexeynobody/flutter-app-environment"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-nobody%2Fflutter-app-environment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-nobody%2Fflutter-app-environment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-nobody%2Fflutter-app-environment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-nobody%2Fflutter-app-environment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexey-nobody","download_url":"https://codeload.github.com/alexey-nobody/flutter-app-environment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248713786,"owners_count":21149775,"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":["dart","dartlang","flutter","flutter-package","flutter-plugin"],"created_at":"2024-09-30T16:39:59.225Z","updated_at":"2026-01-08T16:20:39.466Z","avatar_url":"https://github.com/alexey-nobody.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flutter App Environment\nA simple solution to manage environment variables using `.json` or `.env` files.\n\n---\n\n## Links\n\n- See [CHANGELOG.md](./CHANGELOG.md) for major/breaking updates.\n- Check out the [Example](./example/) for a detailed explanation of all features.\n\n---\n\n## Installation\n\nTo install the package, run the following command:\n\n```sh\nflutter pub add flutter_app_environment\n```\n\n---\n\n## Managing Environment Variables from a `.json` File\n\n### Requirements\n\nBefore initializing the environment, ensure the following:\n\n```dart\nWidgetsFlutterBinding.ensureInitialized();\n```\n\nAdd the configuration files path to **pubspec.yaml**:\n\n```yaml\nflutter:\n  assets:\n    - res/config/\n```\n\n- For **EnvironmentType.development**, use `development.json` or `development.env` as the configuration file.\n- For **EnvironmentType.test**, use `test.json` or `test.env` as the configuration file.\n- For **EnvironmentType.production**, use `production.json` or `production.env` as the configuration file.\n\n### Usage with `.json`: Three Simple Steps\n\n1. **Create the Config**\n\n    ```dart\n    @JsonSerializable(createToJson: false)\n    class EnvironmentConfig {\n      const EnvironmentConfig({\n        required this.title,\n        required this.initialCounter,\n      });\n\n      factory EnvironmentConfig.fromJson(Map\u003cString, dynamic\u003e json) =\u003e\n          _$EnvironmentConfigFromJson(json);\n\n      final String title;\n      final int initialCounter;\n    }\n    ```\n\n2. **Initialize the Environment**\n\n    ```dart\n    WidgetsFlutterBinding.ensureInitialized();\n\n    await Environment.init\u003cEnvironmentConfig, EnvironmentType\u003e(\n      environmentType: EnvironmentType.development,\n      parser: EnvironmentConfig.fromJson,\n    );\n    ```\n\n3. **Use the Config**\n\n    ```dart\n    home: HomePage(\n      title: Environment\u003cEnvironmentConfig\u003e.instance().config.title,\n    ),\n    ```\n\n---\n\n## Managing Environment Variables with Custom Types\n\n1. **Create a Custom Environment Type**\n\n    ```dart\n    enum CustomEnvironmentType { dev, stage, prod }\n    ```\n\n2. **Initialize the Environment**\n\n    ```dart\n    await Environment.init\u003cEnvironmentConfig, CustomEnvironmentType\u003e(\n      environmentType: CustomEnvironmentType.stage,\n      parser: EnvironmentConfig.fromJson,\n    );\n    ```\n\n---\n\n## Managing Environment Variables from a `.env` File\n\nInitialize the environment by specifying `EnvironmentSourceType.env`:\n\n```dart\nawait Environment.init\u003cEnvironmentConfig, EnvironmentType\u003e(\n  environmentType: EnvironmentType.development,\n  source: EnvironmentSourceType.env,\n  parser: EnvironmentConfig.fromJson,\n);\n```\n\n### `.env` File Format\n\nThe parser supports:\n- Basic key-value pairs.\n- Comments (lines starting with `#`).\n- Trailing comments.\n- Quoted values (single and double quotes).\n- Automatic type inference for `int`, `double`, and `bool`.\n\n```env\nTITLE=Environment Development\nINITIAL_COUNTER=10\nIS_DEBUG=true\n# This is a comment\nAPI_KEY=\"your_secret_key\"\n```\n\n---\n\n### Example Project Structure\n\nFor a better understanding, here's an example of how your project structure might look when handling environment variables:\n\n```\nyour_project/\n│\n├── res/\n│   └── config/\n│       ├── development.json\n│       ├── test.json\n│       ├── production.json\n│       └── development.env\n│\n├── lib/\n│   ├── main.dart\n│   └── environment_config.dart\n│\n└── pubspec.yaml\n```\n\nIn this example, JSON configuration files are stored in the `res/config/` folder and declared in `pubspec.yaml`. The environment configuration is loaded in `main.dart` and used throughout the app.\n\n---\n\n### Notes\n\n- Make sure to call `WidgetsFlutterBinding.ensureInitialized()` before initializing the environment.\n- The `EnvironmentConfig` class should match the structure of your `.json` or `.env` files.\n- You can switch between different environment types depending on your build (development, test, production) or create custom environment types.\n\n---\n\n## Contribute\n\nFeel free to fork, improve, submit pull requests, or report issues. I’ll be happy to fix bugs or enhance the extension based on your feedback.\n\n---\n\n### License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexey-nobody%2Fflutter-app-environment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexey-nobody%2Fflutter-app-environment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexey-nobody%2Fflutter-app-environment/lists"}