arcAddRoute function

void arcAddRoute(
  1. String nameRoute
)

Implementation

void arcAddRoute(String nameRoute) {
  var routesFile = File(Structure.replaceAsExpected(
      path: 'lib/infrastructure/navigation/routes.dart'));
  var lines = <String>[];
  if (!routesFile.existsSync()) {
    ArcRouteSample(nameRoute.snakeCase.toUpperCase()).create();
    lines = routesFile.readAsLinesSync();
  } else {
    var content = formatterDartFile(routesFile.readAsStringSync());
    lines = LineSplitter.split(content).toList();
  }

  var line =
      'static const ${nameRoute.snakeCase.toUpperCase()} = \'/${nameRoute.snakeCase.toLowerCase().replaceAll('_', '-')}\';';
  if (lines.contains(line)) {
    return;
  }
  while (lines.last.isEmpty) {
    lines.removeLast();
  }

  lines.add(line);

  _routesSort(lines);

  writeFile(routesFile.path, lines.join('\n'), overwrite: true);
  LogService.success(
      Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute]));
  addNavigation(nameRoute);
}