getUrl method

String getUrl(
  1. String name
)

Resolves a dotted name (e.g. 'auth.login') to a full URL string.

Throws UrlDoestNotExists if any segment in name is not registered. Returns the dev URL in debug mode and the production URL otherwise.

Implementation

String getUrl(String name) {
  List<String> nameParts = name.split('.');
  String url = '';

  BaseUrl? ce = urls.firstWhereOrNull((e) => e.name == nameParts[0]);
  if (ce == null) {
    throw UrlDoestNotExists();
  }
  url += ce.path;
  int i = 1;
  while (i < nameParts.length) {
    ce = ce!.items.firstWhereOrNull((e) => e.name == nameParts[i]);
    if (ce == null) {
      throw UrlDoestNotExists();
    }
    url += ce.path;
    i++;
  }
    if (kDebugMode) {
    return '$baseUrlDev$url';
  }
  return '$baseUrl$url';
}