flutter_flavor_manager 1.0.0
flutter_flavor_manager: ^1.0.0 copied to clipboard
A comprehensive tool for setting up and managing flavors (environments) in Flutter projects for both Android and iOS.
Flutter Flavor Manager #
A comprehensive, production-ready tool for setting up and managing flavors (environments) in Flutter projects. Built with SOLID principles for maintainability and extensibility.
π― Features #
- β
Android Configuration: Automatic product flavor Manager in
build.gradle/build.gradle.kts - β iOS Configuration: Xcode scheme and build configuration generation
- β Dart Entry Points: Automatic generation of flavor-specific main files
- β IDE Support: VSCode/Cursor launch configuration generation
- β Existing Flavor Management: Smart detection and merging of existing flavors
- β Clean Architecture: Built following SOLID principles for easy maintenance
- β Type Safety: Full Dart type safety with comprehensive error handling
π¦ Installation #
As a development dependency #
Add to your pubspec.yaml:
dev_dependencies:
flutter_flavor_manager: ^1.0.0
Then run:
flutter pub get
As a global tool #
dart pub global activate flutter_flavor_manager
π Usage #
CLI Usage #
Run the setup wizard:
# If installed as dev dependency
dart run flutter_flavor_manager
# If installed globally
flutter_flavor_manager
The wizard will guide you through:
- App Name: Enter your application name
- Bundle ID: iOS bundle identifier (e.g.,
com.example.myapp) - Package Name: Android package name (e.g.,
com.example.myapp) - Flavors: Comma-separated list (e.g.,
dev,qa,prod)
Example #
$ dart run flutter_flavor_manager
Enter your app name: My Awesome App
Enter your iOS base bundle ID: com.example.myapp
Enter your Android package name: com.example.myapp
Enter flavors separated by commas: dev,qa,prod
π Starting flavor setup for: dev, qa, prod
π± App Name: My Awesome App
π iOS Bundle ID: com.example.myapp
π€ Android Package: com.example.myapp
π App File: lib/my_awesome_app.dart
β
All done! Flavors setup complete π
Programmatic Usage #
import 'package:flutter_flavor_manager/flutter_flavor_manager.dart';
Future<void> main() async {
// Create configuration
final config = ProjectConfig(
appName: 'MyApp',
appFileName: 'my_app',
baseBundleId: 'com.example.myapp',
androidPackageName: 'com.example.myapp',
flavors: [
FlavorConfig(
name: 'dev',
displayName: 'MyApp',
bundleId: 'com.example.myapp',
packageName: 'com.example.myapp',
),
FlavorConfig(
name: 'prod',
displayName: 'MyApp',
bundleId: 'com.example.myapp',
packageName: 'com.example.myapp',
),
],
);
// Setup platforms
final androidService = AndroidService();
await androidService.setupFlavors(config);
final iosService = IOSService();
await iosService.setupFlavors(config);
// Setup Dart files
final dartService = DartService();
await dartService.setupDartFiles(config);
}
π Generated Structure #
After running the setup, your project will have:
Android (android/app/build.gradle.kts) #
flavorDimensions += "default"
productFlavors {
create("dev") {
dimension = "default"
applicationIdSuffix = ".dev"
resValue("string", "app_name", "MyApp DEV")
}
create("prod") {
dimension = "default"
resValue("string", "app_name", "MyApp")
}
}
iOS (ios/Runner.xcodeproj/) #
xcshareddata/xcschemes/dev.xcschemexcshareddata/xcschemes/prod.xcscheme- Build configurations:
Debug-dev,Release-dev,Profile-dev, etc.
Dart Files #
lib/
βββ my_app.dart # Main app widget
βββ main_dev.dart # Dev entry point
βββ main_prod.dart # Prod entry point
VSCode Configuration (.vscode/launch.json) #
{
"version": "0.2.0",
"configurations": [
{
"name": "My App - DEV (Debug)",
"request": "launch",
"type": "dart",
"program": "lib/main_dev.dart",
"args": ["--flavor", "dev"],
"flutterMode": "debug"
}
]
}
π Running Flavors #
Command Line #
# Run dev flavor
flutter run --flavor dev -t lib/main_dev.dart
# Run prod flavor in release mode
flutter run --flavor prod -t lib/main_prod.dart --release
VSCode/Cursor #
Use the Run and Debug panel (F5) and select the flavor configuration.
Android Studio #
Select the flavor from the "Build Variants" panel.
ποΈ Architecture #
This package follows SOLID principles:
lib/
βββ src/
β βββ models/ # Data models (FlavorConfig, ProjectConfig)
β βββ services/ # Business logic services
β β βββ android_service.dart
β β βββ ios/ # iOS-specific services
β β βββ dart_service.dart
β β βββ vscode_service.dart
β βββ validators/ # Input and project validation
β βββ utils/ # Utility functions
β βββ cli/ # CLI interface
βββ flutter_flavor_manager.dart # Public API
Key Principles #
- Single Responsibility: Each service handles one specific platform/task
- Open/Closed: Easy to extend with new platforms without modifying existing code
- Dependency Inversion: Services depend on abstractions (interfaces)
- Interface Segregation: Specific interfaces for each service type
Custom Validation #
Add custom validators:
class CustomValidator {
static ValidationResult validateCustomRule(String? input) {
if (input == null || !input.startsWith('custom_')) {
return ValidationResult.invalid('Must start with custom_');
}
return ValidationResult.valid(input);
}
}
π Reserved Keywords #
The following flavor names are reserved and cannot be used:
test(usetesting,beta,staginginstead)androidTestdebug(build type)release(build type)profile(build type)main
π Troubleshooting #
Flavors already exist #
The tool automatically detects existing flavors and offers options:
- Skip existing flavors and add only new ones
- Cancel the setup
Pod install fails #
Ensure you have CocoaPods installed:
sudo gem install cocoapods
Build configuration errors #
The tool creates flavor-specific build configurations (e.g., Debug-dev). Ensure your IDE recognizes these configurations by:
- Closing and reopening the project
- Running
flutter clean - Invalidating caches (Android Studio)
π§ͺ Testing #
This package includes comprehensive unit tests covering all core functionality. To run the tests:
# Run all tests
flutter test
# Run with coverage
flutter test --coverage
# Run specific test file
flutter test test/models/flavor_config_test.dart
Test Coverage:
- β 76 unit tests
- β Models (FlavorConfig, ProjectConfig, SetupResult)
- β Validators (Input validation, Bundle IDs, Flavor names)
- β Utilities (String transformations, Xcode ID generation)
See TEST_SUMMARY.md for detailed test documentation.
π€ Contributing #
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow the existing code style and architecture
- Write tests for new functionality
- Update documentation
- Submit a pull request
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments #
- Built with β€οΈ for the Flutter community
- Inspired by best practices from various flavor management tools
- Architecture follows Clean Code and SOLID principles
π Support #
-
π§ Email: Abdallah Abusnineh
-
π Issues: GitHub Issues
-
π¬ Discussions: GitHub Discussions
Made with β€οΈ by Abdallah Abusnineh