// Package imports: import 'package:built_collection/built_collection.dart'; // Project imports: import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/static/currency_model.dart'; double getExchangeRate(BuiltMap currencyMap, {String fromCurrencyId, String toCurrencyId}) { if ((fromCurrencyId ?? '').isEmpty || (toCurrencyId ?? '').isEmpty) { return 1; } final fromCurrency = currencyMap[fromCurrencyId]; final toCurrency = currencyMap[toCurrencyId]; // TODO replace with data from server final baseCurrency = currencyMap[kCurrencyUSDollar]; if (fromCurrency == baseCurrency) { return toCurrency.exchangeRate; } if (toCurrency == baseCurrency) { return 1 / (fromCurrency?.exchangeRate ?? 1); } return toCurrency.exchangeRate * (1 / fromCurrency.exchangeRate); }