Skip to content

Commit

Permalink
add user defined grouping separator in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
emavgl committed Nov 19, 2023
1 parent 44865f4 commit bdb19a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","native_build":true,"dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_ios-6.2.0/","native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/home/emavgl/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.17/","native_build":true,"dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_android-6.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_macos-3.1.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":false,"dependencies":["url_launcher_linux"]},{"name":"shared_preferences_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.0/","native_build":true,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":["url_launcher_windows"]},{"name":"shared_preferences_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.0/","native_build":true,"dependencies":[]}],"web":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","dependencies":["url_launcher_web"]},{"name":"shared_preferences_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.1/","dependencies":[]},{"name":"system_theme_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme_web-0.0.2/","dependencies":[]},{"name":"url_launcher_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.19/","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"package_info_plus","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"share_plus","dependencies":["url_launcher_web","url_launcher_windows","url_launcher_linux"]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"system_theme","dependencies":["system_theme_web"]},{"name":"system_theme_web","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2023-11-19 14:39:44.413568","version":"3.10.6"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","native_build":true,"dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_ios-6.2.0/","native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/home/emavgl/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.17/","native_build":true,"dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_android-6.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/emavgl/.pub-cache/hosted/pub.dev/sqflite-2.3.0/","native_build":true,"dependencies":[]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_macos-3.1.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":false,"dependencies":["url_launcher_linux"]},{"name":"shared_preferences_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_linux","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.0/","native_build":true,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","native_build":true,"dependencies":["url_launcher_windows"]},{"name":"shared_preferences_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"system_theme","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme-2.3.1/","native_build":true,"dependencies":[]},{"name":"url_launcher_windows","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.0/","native_build":true,"dependencies":[]}],"web":[{"name":"file_picker","path":"/home/emavgl/.pub-cache/hosted/pub.dev/file_picker-6.1.1/","dependencies":[]},{"name":"package_info_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","dependencies":[]},{"name":"share_plus","path":"/home/emavgl/.pub-cache/hosted/pub.dev/share_plus-7.2.1/","dependencies":["url_launcher_web"]},{"name":"shared_preferences_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.1/","dependencies":[]},{"name":"system_theme_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/system_theme_web-0.0.2/","dependencies":[]},{"name":"url_launcher_web","path":"/home/emavgl/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.19/","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"package_info_plus","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"share_plus","dependencies":["url_launcher_web","url_launcher_windows","url_launcher_linux"]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"system_theme","dependencies":["system_theme_web"]},{"name":"system_theme_web","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2023-11-19 14:57:00.643964","version":"3.10.6"}
6 changes: 5 additions & 1 deletion lib/helpers/records-utility-functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ String? getLocaleGroupingSeparator() {
return numberFormatSymbols[existingLocale]?.GROUP_SEP;
}

String? getUserDefinedGroupingSeparator() {
return ServiceConfig.sharedPreferences!.getString("groupSeparator");
}

String getCurrencyValueString(double? value, { turnOffGrouping = false }) {
if (value == null) return "";
NumberFormat numberFormat;
Expand All @@ -62,7 +66,7 @@ String getCurrencyValueString(double? value, { turnOffGrouping = false }) {
bool userDefinedGroupingSeparator = ServiceConfig.sharedPreferences!.containsKey("groupSeparator");
if (!mustRemoveGrouping && userDefinedGroupingSeparator) {
String localeGroupingSeparator = getLocaleGroupingSeparator()!;
String groupingSeparatorByTheUser = ServiceConfig.sharedPreferences!.getString("groupSeparator")!;
String groupingSeparatorByTheUser = getUserDefinedGroupingSeparator()!;
result = result.replaceAll(localeGroupingSeparator, groupingSeparatorByTheUser);
}
return result;
Expand Down
18 changes: 18 additions & 0 deletions lib/records/edit-record-page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
Expand All @@ -19,6 +20,7 @@ import 'package:piggybank/premium/splash-screen.dart';
import 'package:piggybank/premium/util-widgets.dart';
import 'package:piggybank/services/database/database-interface.dart';
import 'package:piggybank/services/service-config.dart';
import 'package:shared_preferences/shared_preferences.dart';
import './i18n/edit-record-page.i18n.dart';
import 'package:intl/src/intl_helpers.dart' as helpers;

Expand Down Expand Up @@ -89,6 +91,10 @@ class EditRecordPageState extends State<EditRecordPage> {
if (localeName == null) return false;
return numberFormatSymbols.containsKey(localeName);
}

static String? getUserDefinedGroupingSeparator() {
return ServiceConfig.sharedPreferences?.getString("groupSeparator");
}

String? tryParseMathExpr(String text) {
String myLocale = I18n.locale.toString();
Expand All @@ -100,6 +106,12 @@ class EditRecordPageState extends State<EditRecordPage> {
String groupingSep = numberFormatSymbols[existingLocale]?.GROUP_SEP;
if (isMathExpression(text)) {
try {
// Clean up from user defined grouping separator if they ever
// end up here
var userDefinedGroupingSeparator = getUserDefinedGroupingSeparator();
if (userDefinedGroupingSeparator != null) {
text = text.replaceAll(userDefinedGroupingSeparator, "");
}
text = text.replaceAll(groupingSep, "");
text = text.replaceAll(decimalSep, ".");
return text;
Expand Down Expand Up @@ -139,6 +151,12 @@ class EditRecordPageState extends State<EditRecordPage> {
try {
Locale myLocale = I18n.locale;
Intl.defaultLocale = myLocale.toString();
// Clean up from user defined grouping separator if they ever
// end up here
var userDefinedGroupingSeparator = getUserDefinedGroupingSeparator();
if (userDefinedGroupingSeparator != null) {
toParse = toParse.replaceAll(userDefinedGroupingSeparator, "");
}
num f = NumberFormat().parse(toParse);
return f.toDouble();
} catch (e) {
Expand Down

0 comments on commit bdb19a0

Please sign in to comment.