setBaseUrl method

Future<void> setBaseUrl(
  1. String url
)

Set base URL (will also try to match an environment)

Implementation

Future<void> setBaseUrl(String url) async {
  _currentBaseUrl = url;
  await DevToolsPreferences.saveData(key: _baseUrlKey, value: url);

  // Try to match an environment
  final matchedEnv = _environments.where((e) => e.baseUrl == url).firstOrNull;
  if (matchedEnv != null) {
    _currentEnvironmentName = matchedEnv.name;
    await DevToolsPreferences.saveData(
      key: _environmentNameKey,
      value: matchedEnv.name,
    );
  } else {
    _currentEnvironmentName = 'Custom';
    await DevToolsPreferences.saveData(
      key: _environmentNameKey,
      value: 'Custom',
    );
  }

  await onReinitializeDio?.call();
}