makePage static method
dynamic
makePage(})
Creates a new Page.
Implementation
static makePage(String className, String value,
{String folderPath = pagesFolder,
bool forceCreate = false,
bool addToRoute = true,
bool isInitialPage = false,
bool isAuthPage = false,
String? creationPath}) async {
String name = className.snakeCase.replaceAll(RegExp(r'(_?page)'), "");
// create missing directories in the project
await createDirectoriesFromCreationPath(creationPath, folderPath);
// create file path
String filePath = createPathForDartFile(
folderPath: folderPath,
className: name,
prefix: "page",
creationPath: creationPath);
await _makeDirectory(folderPath);
await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
await _createNewFile(filePath, value, onSuccess: () {
MetroConsole.writeInGreen('[Page] ${name.snakeCase}_page created 🎉');
});
// add to router
if (addToRoute == false) return;
String classImport =
"import '/resources/pages/${creationPath != null ? '$creationPath/' : ''}${name.snakeCase}_page.dart';";
await addToRouter(
classImport: classImport,
createTemplate: (file) {
String strAuthPage = "";
if (isAuthPage) {
strAuthPage = ", authenticatedRoute: true";
}
String strInitialPage = "";
if (isInitialPage) {
strInitialPage = ", initialRoute: true";
}
String routeName =
'router.add(${name.pascalCase}Page.path$strAuthPage$strInitialPage);';
if (file.contains(routeName)) {
return "";
}
RegExp reg = RegExp(r'\}\);(?![\s\S]*\}\);)');
return file.replaceFirst(reg, " $routeName\n});");
});
}