diff --git a/lib/pages/exchange_view/exchange_form.dart b/lib/pages/exchange_view/exchange_form.dart index 3d4dcfcde..e7b2f79af 100644 --- a/lib/pages/exchange_view/exchange_form.dart +++ b/lib/pages/exchange_view/exchange_form.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:intl/intl.dart'; import 'package:isar/isar.dart'; import 'package:stackwallet/models/exchange/aggregate_currency.dart'; import 'package:stackwallet/models/exchange/incomplete_exchange.dart'; @@ -109,7 +110,7 @@ class _ExchangeFormState extends ConsumerState { _sendFieldOnChangedTimer?.cancel(); _sendFieldOnChangedTimer = Timer(_valueCheckInterval, () async { - final newFromAmount = Decimal.tryParse(value); + final newFromAmount = _localizedStringToNum(value); await ref .read(exchangeFormStateProvider) @@ -123,7 +124,7 @@ class _ExchangeFormState extends ConsumerState { _receiveFieldOnChangedTimer?.cancel(); _receiveFieldOnChangedTimer = Timer(_valueCheckInterval, () async { - final newToAmount = Decimal.tryParse(value); + final newToAmount = _localizedStringToNum(value); await ref .read(exchangeFormStateProvider) @@ -131,6 +132,20 @@ class _ExchangeFormState extends ConsumerState { }); } + Decimal? _localizedStringToNum(String? value) { + if (value == null) { + return null; + } + try { + final numFromLocalised = NumberFormat.decimalPattern( + ref.read(localeServiceChangeNotifierProvider).locale) + .parse(value); + return Decimal.tryParse(numFromLocalised.toString()); + } catch (_) { + return null; + } + } + Future _getAggregateCurrency(Currency currency) async { final rateType = ref.read(exchangeFormStateProvider).exchangeRateType; final currencies = await ExchangeDataLoadingService.instance.isar.currencies