addRoute function
This command will create the route to the new page
Implementation
void addRoute(String nameRoute, String bindingDir, String viewDir) {
var routesFile = findFileByName('app_routes.dart');
// var content = '';
if (routesFile.path.isEmpty) {
RouteSample().create();
routesFile = File(RouteSample().path);
// content = routesFile.readAsStringSync();
}
var pathSplit = viewDir.split('/');
///remove file
pathSplit.removeLast();
///remove view folder
if (PubspecUtils.extraFolder ?? true) {
pathSplit.removeLast();
}
pathSplit.removeWhere((element) => element == 'app' || element == 'modules');
for (var i = 0; i < pathSplit.length; i++) {
pathSplit[i] =
pathSplit[i].snakeCase.snakeCase.toLowerCase().replaceAll('_', '-');
}
var route = pathSplit.join('/');
var declareRoute = 'static const ${nameRoute.snakeCase.toUpperCase()} =';
var line = "$declareRoute '/$route';";
if (supportChildrenRoutes) {
line = '$declareRoute ${_pathsToRoute(pathSplit)};';
var linePath = "$declareRoute '/${pathSplit.last}';";
routesFile.appendClassContent('_Paths', linePath);
}
routesFile.appendClassContent('Routes', line);
addAppPage(nameRoute, bindingDir, viewDir);
LogService.success(
Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute]));
}