execute method
Prompts for build target and flavor if not provided, validates environment, and builds the application using the Flutter CLI.
Implementation
Future<void> execute(List<String> args) async {
if (!ConfigService.isValidProject(_log)) return;
if (!ConfigService.requiresInitialized(_log)) return;
final config = ConfigService.load();
final flavors = config.flavors;
// 1. Resolve Target Type
const validTargets = ['apk', 'appbundle', 'ios', 'ipa'];
String? targetType = args
.where((a) => validTargets.contains(a.toLowerCase()))
.map((a) => a.toLowerCase())
.firstOrNull;
targetType ??= _log.chooseOne(
'👉 Select build target:',
choices: validTargets,
);
// 2. Resolve Flavor
String? flavor;
final otherArgs =
args.where((a) => !validTargets.contains(a.toLowerCase())).toList();
if (otherArgs.isNotEmpty) {
flavor = otherArgs[0].toLowerCase().trim();
if (!flavors.contains(flavor)) {
_log.error('❌ flavor_cli: unknown flavor "$flavor"');
_log.info(' → available flavors: [${flavors.join(", ")}]');
return;
}
}
if (flavor == null) {
flavor = _log.chooseOne('👉 Select a flavor to build:', choices: flavors);
}
// 3. Validate ENV file and entry point
final service = RuntimeConfigService();
if (!service.validateFlavorReadyToRun(config, flavor, _log)) return;
_log.info('🏗️ Building $targetType for flavor: $flavor...');
final processArgs = [
'build',
targetType,
'--release',
...service.buildRunArgs(config, flavor),
];
final process = await Process.start(
'flutter',
processArgs,
mode: ProcessStartMode.inheritStdio,
runInShell: true,
);
exit(await process.exitCode);
}