removeRouteEntry function

String removeRouteEntry(
  1. String content,
  2. String routeName,
  3. String snake
)

Removes a feature's GoRoute(...) block and its view import from a route_page.dart body. snake is the snake_case feature name used to match the <snake>_view.dart import line.

Implementation

String removeRouteEntry(String content, String routeName, String snake) {
  var result = content;

  // Remove the GoRoute block (matches our generated shape).
  final route = RegExp(
    r'\n?[ \t]*GoRoute\(\s*name: AppRoutes\.' +
        RegExp.escape(routeName) +
        r',\s*path: AppRoutes\.' +
        RegExp.escape(routeName) +
        r',\s*builder:[^\n]*\n[ \t]*\),',
  );
  result = result.replaceAll(route, '');

  // Remove the matching view import line.
  final import = RegExp(
    r"\n?import '[^']*" + RegExp.escape('${snake}_view.dart') + r"';",
  );
  result = result.replaceAll(import, '');

  return result;
}