cleanPath function

String cleanPath(
  1. String path
)

Cleans the path by:

  • Removing /api/{something}/ if it exists
  • Removing braces {}
  • Returning the remaining normalized path

Implementation

String cleanPath(String path) {
  // Normalize slashes
  List<String> parts = path.split('/')
    ..removeWhere((p) => p.isEmpty); // remove empty strings from //

  if (parts.isNotEmpty && parts.first.toLowerCase() == 'api') {
    // Remove "api"
    parts.removeAt(0);

    // Remove the next segment (like mobile, warehouseapp, etc.)
    if (parts.isNotEmpty) {
      parts.removeAt(0);
    }
  }

  return parts.join('/').replaceAll('{', '').replaceAll('}', '');
}