createWidgetProcess method
Future<void>
createWidgetProcess(- {required String widgetName,
- required String destinationPath,
- required bool isCommon}
)
Implementation
Future<void> createWidgetProcess({
required String widgetName,
required String destinationPath,
required bool isCommon,
}) async {
String destinationFilePath = destinationPath;
if (!isCommon) {
destinationFilePath = "$destinationFilePath$kWidgetPath";
}
destinationFilePath = "$destinationFilePath$widgetName$kDart";
if (Utility.doesFileExist(filePath: destinationFilePath)) {
Utility.errorPrinter(text: '$widgetName $kWidgetAlreadyExistError');
exit(1);
}
try {
destinationPath = isCommon
? destinationPath
: '$destinationPath$kWidgetWithoutEndSlashPath';
await Utility.copyFolder(
sourcePath: Utility.getDirFromCliPackage(
sourceFolderPath: kWidgetSnippetPath,
),
destinationPath: destinationPath,
);
await Utility.renameFilesWithSubstring(
path: destinationPath,
substring: kBasicWidgetLowerCase,
newName: widgetName,
);
String targetFileName = isCommon ? '$widgetName$kDart' : kWhitespaces;
await Utility.processFiles(
path: destinationPath,
substring: kStartComment,
replacement: kWhitespaces,
isPascalCase: false,
targetFileName: targetFileName,
);
await Utility.processFiles(
path: destinationPath,
substring: kEndComment,
replacement: kWhitespaces,
isPascalCase: false,
targetFileName: targetFileName,
);
await Utility.processFiles(
path: destinationPath,
substring: kBasicWidget,
replacement: widgetName,
isPascalCase: true,
targetFileName: targetFileName,
);
String? name = Utility.getPubspecInfo();
if (name != null) {
await Utility.processFiles(
path: destinationPath,
substring: kFlutterCleanArchitecture,
replacement: name,
isPascalCase: false,
targetFileName: targetFileName);
}
Utility.successPrinter(
text: '$kWidgetLabel $widgetName $kCreatedAt $destinationPath',
);
} catch (e) {
Utility.errorPrinter(text: '$kError $e');
}
}