Refactor ForexRateAPI integration to load API key from .env file and enhance error handling

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-19 23:48:26 +01:00
parent a775a20dd2
commit e6c16967f9
8 changed files with 244 additions and 81 deletions
+11
View File
@@ -21,6 +21,7 @@ class HomeScreen extends StatelessWidget {
symbol: 'SEK ',
decimalDigits: 2,
);
final rateFormat = NumberFormat('0.000000');
final totalUsd = rows.isEmpty ? 0.0 : rows.last.runningUsd;
final totalSek = rows.isEmpty ? 0.0 : rows.last.runningSek;
@@ -80,6 +81,7 @@ class HomeScreen extends StatelessWidget {
DataColumn(label: Text('Status')),
DataColumn(label: Text('USD')),
DataColumn(label: Text('SEK')),
DataColumn(label: Text('Rate USD->SEK')),
DataColumn(label: Text('Running USD')),
DataColumn(label: Text('Running SEK')),
],
@@ -110,6 +112,15 @@ class HomeScreen extends StatelessWidget {
: sekCurrency.format(row.sekAmount),
),
),
DataCell(
Text(
row.effectiveUsdToSekRate == null
? '-'
: rateFormat.format(
row.effectiveUsdToSekRate,
),
),
),
DataCell(
Text(usdCurrency.format(row.runningUsd)),
),
+5 -1
View File
@@ -91,6 +91,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
content: Text('Backfill finished for last year.'),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(controller.errorMessage!)),
);
}
},
icon: const Icon(Icons.history),
@@ -112,7 +116,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
const SizedBox(height: 16),
const Text(
'ForexRateAPI key is configured in code constant forexRateApiKey.',
'ExchangeratesAPI key is loaded from .env (EXCHANGE_RATE_API_KEY).',
),
],
),