createClone function
Initiates the process of creating a new Flutter project clone.
This function guides the user through collecting basic clone information, creating the necessary directory structure and configuration files, and setting up associated services like package renaming and Firebase.
It includes robust cancellation support: if the user cancels at any stage or an error occurs, any files or directories created during the process will be automatically cleaned up to maintain a clean state.
Throws an Exception if an unhandled error occurs during the clone creation process.
Implementation
Future<void> createClone() async {
logger.i('π Creating a new project clone...');
try {
// Step 1: Collect clone configuration
final config = _promptCloneBasicInfo();
if (config == null) {
logger.w('β οΈ Clone creation cancelled by user');
_cleanupCloneCreation();
return;
}
// Step 2: Create directory structure and config file
if (!_createCloneStructure(config)) {
_cleanupCloneCreation();
return;
}
// Step 3: Setup services (rename, Firebase, assets)
if (!await _setupCloneServices(config)) {
_cleanupCloneCreation();
return;
}
// Step 4: Create assets directory
if (!createCloneAssetsDirectory(config['clientId']!, [
config['launcherIcon']!,
config['splashScreen']!,
config['logo']!,
])) {
_cleanupCloneCreation();
return;
}
// Success!
logger.i('π Clone successfully created for ${config['clientId']}!');
logger.i(
'π Run "clonify configure --clientId ${config['clientId']}" to generate this clone.',
);
// Clear tracking list on successful completion
_createdClonePaths.clear();
} catch (e) {
logger.e('β Error during clone creation: $e');
_cleanupCloneCreation();
rethrow;
}
}