fix .env loading

This commit is contained in:
Rene Kievits
2025-10-30 18:02:06 +01:00
parent 78fc69aeb4
commit cafec12888
2 changed files with 11 additions and 4 deletions

View File

@@ -100,7 +100,15 @@ class DeckRepository {
}
Future<String?> loadApiKey() async {
final envApiKey = dotenv.env['WANIKANI_API_KEY'];
String? envApiKey;
try {
envApiKey = dotenv.env['WANIKANI_API_KEY'];
} catch (e) {
// dotenv is not initialized, so we can't get the key.
// This is expected in release builds.
envApiKey = null;
}
if (envApiKey != null && envApiKey.isNotEmpty) {
_apiKey = envApiKey;
return _apiKey;
@@ -405,4 +413,4 @@ class DeckRepository {
await saveVocabulary(items);
return items;
}
}
}