diff --git a/Frontend/lib/mih_packages/calculator/package_tools/currency_exchange_rate.dart b/Frontend/lib/mih_packages/calculator/package_tools/currency_exchange_rate.dart index 0b077a11..762dbc5f 100644 --- a/Frontend/lib/mih_packages/calculator/package_tools/currency_exchange_rate.dart +++ b/Frontend/lib/mih_packages/calculator/package_tools/currency_exchange_rate.dart @@ -30,19 +30,21 @@ class _CurrencyExchangeRateState extends State { Future submitForm() async { String fromCurrencyCode = _fromCurrencyController.text.split(" - ")[0]; String toCurrencyCode = _toCurrencyController.text.split(" - ")[0]; + List dateValue = []; double exchangeRate = 0; await MihCurrencyExchangeRateServices.getCurrencyExchangeValue( fromCurrencyCode, toCurrencyCode) .then((amount) { - exchangeRate = amount; + dateValue = amount; }); + exchangeRate = double.parse(dateValue[1]); double exchangeValue = double.parse(_fromAmountController.text) * exchangeRate; print( - "${_fromAmountController.text} | $fromCurrencyCode\n$exchangeValue | $toCurrencyCode"); - displayResult(_fromAmountController.text, fromCurrencyCode, exchangeValue, - toCurrencyCode); + "Date: ${dateValue[0]}\n${_fromAmountController.text} | $fromCurrencyCode\n$exchangeValue | $toCurrencyCode"); + displayResult(dateValue[0], _fromAmountController.text, fromCurrencyCode, + exchangeValue, toCurrencyCode); } void clearInput() { @@ -52,7 +54,7 @@ class _CurrencyExchangeRateState extends State { _toAmountController.clear(); } - void displayResult(String amount, String fromCurrencyCode, + void displayResult(String date, String amount, String fromCurrencyCode, double exchangeValue, String toCurrencyCode) { showDialog( context: context, @@ -71,6 +73,19 @@ class _CurrencyExchangeRateState extends State { color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), const SizedBox(height: 20), + FittedBox( + child: Text( + "Values as at $date", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 30, + fontWeight: FontWeight.bold, + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/Frontend/lib/mih_services/mih_currency_exchange_rate_services.dart b/Frontend/lib/mih_services/mih_currency_exchange_rate_services.dart index 091a2554..2be8748e 100644 --- a/Frontend/lib/mih_services/mih_currency_exchange_rate_services.dart +++ b/Frontend/lib/mih_services/mih_currency_exchange_rate_services.dart @@ -38,7 +38,7 @@ class MihCurrencyExchangeRateServices { } } - static Future getCurrencyExchangeValue( + static Future> getCurrencyExchangeValue( String fromCurrencyCode, String toCurrencyCode, ) async { @@ -48,19 +48,19 @@ class MihCurrencyExchangeRateServices { final Map jsonResponse = json.decode(response.body); final Map? baseCurrencyData = jsonResponse[fromCurrencyCode]; - + final List dateValue = []; if (baseCurrencyData != null) { - // Access the value for the target currency (e.g., "usd") final dynamic rateValue = baseCurrencyData[toCurrencyCode]; + final String date = jsonResponse["date"]; if (rateValue is num) { - // Check if it's a number (int or double) - return rateValue.toDouble(); + dateValue.add(date); + dateValue.add(rateValue.toString()); + return dateValue; } else { - // Handle cases where the rate might not be a number or is missing print( 'Warning: Rate for $toCurrencyCode in $fromCurrencyCode is not a number or missing.'); - return 0; + return ["Error", "0"]; } } else { throw Exception(