diff --git a/lib/constants.dart b/lib/constants.dart index f9e53d1cc..ea76b17e5 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -649,6 +649,10 @@ const String kDefaultLightSelectedColorMenu = '#f2faff'; const String kDefaultLightSelectedColor = '#e5f5ff'; const String kDefaultLightBorderColor = '#dfdfdf'; +const String kTaxRegionUnitedStates = 'US'; +const String kTaxRegionEurope = 'EU'; +const String kTaxRegionAustralia = 'AU'; + const String kReportGroupDay = 'day'; const String kReportGroupWeek = 'week'; const String kReportGroupMonth = 'month'; diff --git a/lib/redux/static/static_selectors.dart b/lib/redux/static/static_selectors.dart index a78b8ae29..4c3152c0d 100644 --- a/lib/redux/static/static_selectors.dart +++ b/lib/redux/static/static_selectors.dart @@ -20,6 +20,19 @@ List countryList(BuiltMap countryMap) { return list; } +var memoizedCountryIso2Map = memo1( + (BuiltMap countryMap) => countryIso2Map(countryMap)); + +Map countryIso2Map( + BuiltMap countryMap) { + final map = {}; + countryMap.keys.forEach((countryId) { + final country = countryMap[countryId]; + map[country.iso2] = country; + }); + return map; +} + var memoizedGroupList = memo1((BuiltMap groupMap) => groupList(groupMap)); diff --git a/lib/ui/settings/tax_settings.dart b/lib/ui/settings/tax_settings.dart index bb900574a..4fed7e99f 100644 --- a/lib/ui/settings/tax_settings.dart +++ b/lib/ui/settings/tax_settings.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'package:flutter/material.dart'; import 'package:invoiceninja_flutter/constants.dart'; +import 'package:invoiceninja_flutter/redux/static/static_selectors.dart'; // Package imports: import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -32,6 +33,11 @@ class _TaxSettingsState extends State { static final GlobalKey _formKey = GlobalKey(debugLabel: '_taxSettings'); FocusScopeNode _focusNode; + final Map _showDetails = { + kTaxRegionUnitedStates: false, + kTaxRegionEurope: false, + kTaxRegionAustralia: false, + }; @override void initState() { @@ -54,12 +60,13 @@ class _TaxSettingsState extends State { final state = viewModel.state; final taxData = company.taxData; + final countryMap = memoizedCountryIso2Map(state.staticState.countryMap); List subregions = []; - String region = 'EU'; + String region = kTaxRegionEurope; if (company.settings.countryId == kCountryUnitedStates) { - region = 'US'; + region = kTaxRegionUnitedStates; } else if (company.settings.countryId == kCountryAustralia) { - region = 'AU'; + region = kTaxRegionAustralia; } subregions = taxData.regions[region].subregions.keys.toList(); @@ -179,18 +186,37 @@ class _TaxSettingsState extends State { .map((code) => DropdownMenuItem(child: Text(code), value: code)) .toList()), - ...taxData.regions.keys - .map((region) => Column( + SizedBox(height: 12), + ...taxData.regions.keys.map((region) { + return Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Row( children: [ - Text(region), - /* - ...taxData.regions[region].subregions.keys - .map((subregion) => Text(subregion)) - .toList(), - */ + Expanded( + child: + Text(countryMap[region]?.name ?? region)), + TextButton( + onPressed: () { + setState(() { + _showDetails[region] = + !_showDetails[region]; + }); + }, + child: Text(_showDetails[region] + ? localization.hideDetails + : localization.showDetails)) ], - )) - .toList(), + ), + ), + if (_showDetails[region]) + ...taxData.regions[region].subregions.keys + .map((subregion) => Text(subregion)) + .toList(), + ], + ); + }).toList(), ] ], ) diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 4e26d697a..3ed3005ab 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -18,6 +18,8 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'hide_details': 'Hide Details', + 'show_details': 'Show Details', 'version': 'version', 'seller_subregion': 'Seller Subregion', 'calculate_taxes': 'Calculate Taxes', @@ -98328,6 +98330,14 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['version'] ?? _localizedValues['en']['version']; + String get hideDetails => + _localizedValues[localeCode]['hide_details'] ?? + _localizedValues['en']['hide_details']; + + String get showDetails => + _localizedValues[localeCode]['show_details'] ?? + _localizedValues['en']['show_details']; + // STARTER: lang field - do not remove comment String lookup(String key) {