createFlutterProject method
Future<void>
createFlutterProject({
- required String projectName,
- required String organizationName,
- required List<
PlatformType> platforms, - required MobilePlatform mobilePlatform,
- required DesktopPlatform desktopPlatform,
- CustomDesktopPlatforms? customDesktopPlatforms,
override
Implementation
@override
Future<void> createFlutterProject({
required String projectName,
required String organizationName,
required List<PlatformType> platforms,
required MobilePlatform mobilePlatform,
required DesktopPlatform desktopPlatform,
CustomDesktopPlatforms? customDesktopPlatforms,
}) async {
final args = ['create', '--org', organizationName];
// Collect all platforms in a single list
final allPlatforms = <String>[];
// Add mobile platforms
if (platforms.contains(PlatformType.mobile)) {
if (mobilePlatform == MobilePlatform.android || mobilePlatform == MobilePlatform.both) {
allPlatforms.add('android');
}
if (mobilePlatform == MobilePlatform.ios || mobilePlatform == MobilePlatform.both) {
allPlatforms.add('ios');
}
}
// Add web platform
if (platforms.contains(PlatformType.web)) {
allPlatforms.add('web');
}
// Add desktop platforms
if (platforms.contains(PlatformType.desktop)) {
if (desktopPlatform == DesktopPlatform.custom && customDesktopPlatforms != null) {
if (customDesktopPlatforms.windows) allPlatforms.add('windows');
if (customDesktopPlatforms.macos) allPlatforms.add('macos');
if (customDesktopPlatforms.linux) allPlatforms.add('linux');
} else {
if (desktopPlatform == DesktopPlatform.windows || desktopPlatform == DesktopPlatform.all) {
allPlatforms.add('windows');
}
if (desktopPlatform == DesktopPlatform.macos || desktopPlatform == DesktopPlatform.all) {
allPlatforms.add('macos');
}
if (desktopPlatform == DesktopPlatform.linux || desktopPlatform == DesktopPlatform.all) {
allPlatforms.add('linux');
}
}
}
// Add single --platforms flag with all platforms combined
if (allPlatforms.isNotEmpty) {
args.add('--platforms=${allPlatforms.join(',')}');
}
args.add(projectName);
final result = await Process.run(
'flutter',
args,
workingDirectory: Directory.current.path,
);
if (result.exitCode != 0) {
throw FlutterCommandException(
'Failed to create Flutter project: ${result.stderr}',
);
}
}