saveDefaultApiKey static method
Save the default API key for a specific service type
Implementation
static Future<void> saveDefaultApiKey(
String serviceType, String keyName) async {
await _prefs!.setString('default_api_key_$serviceType', keyName);
List<ApiKeyModel> apiKeys = await getApiKeys();
apiKeys = apiKeys.map((apiKey) {
if (apiKey.serviceType == serviceType) {
return ApiKeyModel(
name: apiKey.name,
key: apiKey.key,
serviceType: serviceType,
isDefault: apiKey.name == keyName,
);
} else {
return apiKey;
}
}).toList();
await saveApiKeys(apiKeys);
}