makeNavigationHub static method
dynamic
makeNavigationHub(
Creates a new Navigation Hub.
Implementation
static makeNavigationHub(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'(_?navigation_hub)'), "");
// create missing directories in the project
await createDirectoriesFromCreationPath(creationPath, folderPath);
// create file path
String filePath = createPathForDartFile(
folderPath: folderPath,
className: name,
prefix: "navigation_hub",
creationPath: creationPath);
await _makeDirectory(folderPath);
await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
await _createNewFile(filePath, value, onSuccess: () {
MetroConsole.writeInGreen(
'[Navigation Hub] ${name.snakeCase}_navigation_hub created 🎉');
});
// add to router
if (addToRoute == false) return;
String classImport =
"import '/resources/pages/${creationPath != null ? '$creationPath/' : ''}${name.snakeCase}_navigation_hub.dart';";
await addToRouter(
classImport: classImport,
createTemplate: (file) {
String strAuthPage = "";
if (isAuthPage) {
strAuthPage = ", authPage: true";
}
String strInitialPage = "";
if (isInitialPage) {
strInitialPage = ", initialRoute: true";
}
String routeName =
'router.add(${name.pascalCase}NavigationHub.path$strAuthPage$strInitialPage);';
if (file.contains(routeName)) {
return "";
}
RegExp reg = RegExp(r'\}\);(?![\s\S]*\}\);)');
return file.replaceFirst(reg, " $routeName\n});");
});
}