Flutter Env Config
A powerful and flexible environment configuration management package for Flutter projects. This package simplifies managing and switching between multiple environment configurations (e.g., dev
, staging
, prod
) and allows runtime updates, making it ideal for scalable applications.
Features
- Load environment configurations from JSON or YAML files.
- Dynamic configuration updates at runtime using
ValueNotifier
. - Centralized environment management with a singleton pattern.
- Supports CI/CD configurations, API settings, theming, analytics, and more.
- Easy-to-use methods for testing and environment overrides.
General Configurations:
- Define environments such as dev, staging, and prod.
- Access environment-specific settings like name, api, and features.
"dev": {
"environment": "dev",
"name": "Development"
}
API Settings:
- Configure the base URL and timeout for API calls.
"api": {
"baseUrl": "https://dev.api.com",
"timeout": 30000
}
CI/CD Integration:
- Add CI/CD variables like API keys and database URLs.
- Track builds with buildId, branchName, and commitHash.
- Set up deployment settings, including rollback on failure.
- Enable unit, integration, and end-to-end tests with threshold configurations.
"ciCd": {
"variables": {
"apiKeyEnvVar": "DEV_API_KEY",
"databaseUrlEnvVar": "DEV_DATABASE_URL"
},
"build": {
"buildId": "12345",
"branchName": "dev",
"commitHash": "dev123hash"
},
"deployment": {
"server": "https://dev.server.com",
"artifactName": "dev_app_build.apk",
"rollbackOnFailure": true,
"deploymentId": "",
"environment": "",
"url": ""
},
"testing": {
"runUnitTests": true,
"coverageThreshold": 70,
"testingFramework": "",
"enableUnitTests": false,
"enableIntegrationTests": false,
"enableE2ETests": false
}
}
Feature Toggles:
- Enable or disable beta features dynamically.
- Use feature flags to control app features at runtime.
"features": {
"enableBetaFeatures": true,
"featureFlag": true,
"featureOneEnabled": false,
"featureTwoEnabled": false
}
Logging:
- Manage application logging with options for log levels (debug, info, etc.).
- Enable or disable logging.
"logging": {
"logLevel": "debug",
"enableLogging": true
}
Security:
- Enable encryption for sensitive data.
- Support secure storage and SSL pinning.
"security": {
"enableEncryption": true,
"encryptionKey": "",
"enableSecureStorage": true,
"sslPinning": false
}
Analytics:
- Configure analytics with API keys.
- Enable or disable user tracking.
"analytics": {
"enableAnalytics": true,
"apiKey": "DEV_ANALYTICS_KEY",
"enableTracking": true
}
Localization:
- Set a default locale (e.g., en) and define supported locales (e.g., en, fr, es).
"localization": {
"defaultLocale": "en",
"supportedLocales": [
"en",
"fr",
"es"
]
}
Theming:
- Define primary and secondary colors for the app.
- Customize fonts with a specified font family.
"theming": {
"primaryColor": "#FF5733",
"secondaryColor": "#33FF57",
"fontFamily": "Roboto"
}
Third-Party Integrations:
- Integrate Firebase with options like apiKey, projectId, and authDomain.
- Support payment gateways like Razorpay and Stripe.
"thirdPartyServices": {
"firebaseConfig": {
"apiKey": "DEV_FIREBASE_KEY",
"projectId": "dev-project-id",
"appId": "",
"messagingSenderId": "",
"storageBucket": "",
"authDomain": "",
"measurementId": ""
},
"enablePaymentGateway": true,
"enableAnalyticsIntegration": true,
"razorpayConfig": {
"apiKey": "",
"secretKey": ""
},
"stripeConfig": {
"publishableKey": "",
"secretKey": ""
}
}
Scheduled Tasks:
- Automate sync and cleanup tasks with defined intervals.
"scheduledTasks": {
"tasks": [],
"syncInterval": 300,
"cleanupInterval": 600
}
How to Use
Follow these steps to seamlessly integrate environment-specific configurations into your Flutter app:
-
Install the Package
Add the package to your
pubspec.yaml
:
dependencies:
flutter_env_config: <latest-version>
-
Generate Config Files
Run the following command in your terminal:
generate-config
This will create an assets
folder in your project with two files:
config.json
& config.yaml
-
Register Assets
Include the
assets
folder in your pubspec.yaml:
flutter:
assets:
- assets/
-
Initialize Before runApp
Set up the configuration during app startup before runApp():
await FlutterEnvConfig.init(
configFile: 'assets/config.json',
targetEnvironment: Environment.dev,
);
runApp(MyApp());
-
Access Configuration
Easily access the environment data anywhere in your app:
EnvironmentConfig config = EnvironmentManager.environmentData;
📝 Notes
If the assets folder is newly generated, rerun your app to load the files. Modify values in config.json or config.yaml as needed, but rerun the app afterward to apply changes.
Contributing
Contributions are welcome! If you find bugs or have feature suggestions, feel free to create an issue or submit a pull request. Make sure to follow the contribution guidelines.
- Report bugs and request features via GitHub Issues
- Engage in discussions and help users solve their problems/questions in the Discussions
License
This package is licensed under the MIT License. See the LICENSE file for more details.
Happy coding! 🎉
This README.md
covers installation, usage, features, property descriptions, and customization, making it beginner-friendly and informative for all users of the package.
Version: 1.0.2
Author: Atanu Sabyasachi Jena
License: MIT
Libraries
- enums/env_enum
- env_config_wrapper
- flutter_env_config
- models/analytics_config
- models/api_config
- models/ci_cd/build_config
- models/ci_cd/ci_cd_config
- models/ci_cd/deployment_config
- models/ci_cd/testing_config
- models/env_config
- models/features_config
- models/localization_config
- models/logging_config
- models/scheduled_tasks_config
- models/security_config
- models/theming_config
- models/third_oarty_services/firebase_config
- models/third_oarty_services/razor_pay_config
- models/third_oarty_services/stripe_config
- models/third_oarty_services/third_party_services_config