fix: Dart's stupid rounding

This commit is contained in:
julian 2023-05-05 09:32:55 -06:00
parent 22a7763b26
commit 0ca5e46474

View file

@ -5,7 +5,6 @@ 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';
@ -152,10 +151,22 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
return null;
}
try {
final numFromLocalised = NumberFormat.decimalPattern(
ref.read(localeServiceChangeNotifierProvider).locale)
.parse(value);
return Decimal.tryParse(numFromLocalised.toString());
// wtf Dart?????
// This turns "99999999999999999999" into 100000000000000000000.0
// final numFromLocalised = NumberFormat.decimalPattern(
// ref.read(localeServiceChangeNotifierProvider).locale)
// .parse(value);
// return Decimal.tryParse(numFromLocalised.toString());
try {
return Decimal.parse(value);
} catch (_) {
try {
return Decimal.parse(value.replaceAll(",", "."));
} catch (_) {
rethrow;
}
}
} catch (_) {
return null;
}