mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
number format hack/fix
This commit is contained in:
parent
983cdca736
commit
27d97ebf49
6 changed files with 24 additions and 20 deletions
|
@ -21,7 +21,7 @@ class LocaleService extends ChangeNotifier {
|
|||
Future<void> loadLocale({bool notify = true}) async {
|
||||
_locale = Platform.isWindows
|
||||
? "en_US"
|
||||
: await Devicelocale.currentLocale ?? "en_US";
|
||||
: (await Devicelocale.currentAsLocale)?.toString() ?? "en_US";
|
||||
if (notify) {
|
||||
notifyListeners();
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:intl/number_symbols.dart';
|
||||
import 'package:intl/number_symbols_data.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
||||
class Amount {
|
||||
Amount({
|
||||
|
@ -52,8 +51,7 @@ class Amount {
|
|||
}
|
||||
|
||||
// get number symbols for decimal place and group separator
|
||||
final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
final numberSymbols = Util.getSymbolsFor(locale: locale);
|
||||
|
||||
final groupSeparator = numberSymbols?.GROUP_SEP ?? ",";
|
||||
final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? ".";
|
||||
|
@ -101,8 +99,7 @@ class Amount {
|
|||
final wholeNumber = decimal.truncate();
|
||||
|
||||
// get number symbols for decimal place and group separator
|
||||
final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
final numberSymbols = Util.getSymbolsFor(locale: locale);
|
||||
|
||||
final String separator = numberSymbols?.DECIMAL_SEP ?? ".";
|
||||
|
||||
|
|
|
@ -22,11 +22,13 @@ final pMaxDecimals = Provider.family<int, Coin>(
|
|||
);
|
||||
|
||||
final pAmountFormatter = Provider.family<AmountFormatter, Coin>((ref, coin) {
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select((value) => value.locale),
|
||||
);
|
||||
|
||||
return AmountFormatter(
|
||||
unit: ref.watch(pAmountUnit(coin)),
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select((value) => value.locale),
|
||||
),
|
||||
locale: locale,
|
||||
coin: coin,
|
||||
maxDecimals: ref.watch(pMaxDecimals(coin)),
|
||||
);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/number_symbols.dart';
|
||||
import 'package:intl/number_symbols_data.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_unit.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
||||
class AmountInputFormatter extends TextInputFormatter {
|
||||
final int decimals;
|
||||
|
@ -20,8 +19,7 @@ class AmountInputFormatter extends TextInputFormatter {
|
|||
TextEditingValue formatEditUpdate(
|
||||
TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
// get number symbols for decimal place and group separator
|
||||
final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
final numberSymbols = Util.getSymbolsFor(locale: locale);
|
||||
|
||||
final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? ".";
|
||||
final groupSeparator = numberSymbols?.GROUP_SEP ?? ",";
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:intl/number_symbols.dart';
|
||||
import 'package:intl/number_symbols_data.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
||||
// preserve index order as index is used to store value in preferences
|
||||
enum AmountUnit {
|
||||
|
@ -188,8 +187,7 @@ extension AmountUnitExt on AmountUnit {
|
|||
}
|
||||
|
||||
// get number symbols for decimal place and group separator
|
||||
final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
final numberSymbols = Util.getSymbolsFor(locale: locale);
|
||||
|
||||
final groupSeparator = numberSymbols?.GROUP_SEP ?? ",";
|
||||
final decimalSeparator = numberSymbols?.DECIMAL_SEP ?? ".";
|
||||
|
@ -237,8 +235,7 @@ extension AmountUnitExt on AmountUnit {
|
|||
String returnValue = wholeNumber.toString();
|
||||
|
||||
// get number symbols for decimal place and group separator
|
||||
final numberSymbols = numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
final numberSymbols = Util.getSymbolsFor(locale: locale);
|
||||
|
||||
// insert group separator
|
||||
final regex = RegExp(r'\B(?=(\d{3})+(?!\d))');
|
||||
|
|
|
@ -14,11 +14,21 @@ import 'dart:io';
|
|||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/number_symbols.dart';
|
||||
import 'package:intl/number_symbols_data.dart';
|
||||
|
||||
abstract class Util {
|
||||
static Directory? libraryPath;
|
||||
static double? screenWidth;
|
||||
|
||||
static NumberSymbols? getSymbolsFor({required String locale}) {
|
||||
return numberFormatSymbols[locale] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.replaceAll("-", "_")] as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(3).toLowerCase()]
|
||||
as NumberSymbols? ??
|
||||
numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?;
|
||||
}
|
||||
|
||||
static bool get isDesktop {
|
||||
// special check for running on linux based phones
|
||||
if (Platform.isLinux && screenWidth != null && screenWidth! < 800) {
|
||||
|
|
Loading…
Reference in a new issue