diff --git a/packages/dart/npt_flutter/lib/features/profile_form/widgets/profile_relay_quick_buttons.dart b/packages/dart/npt_flutter/lib/features/profile_form/widgets/profile_relay_quick_buttons.dart index 2e5ffcfdf..753d7f973 100644 --- a/packages/dart/npt_flutter/lib/features/profile_form/widgets/profile_relay_quick_buttons.dart +++ b/packages/dart/npt_flutter/lib/features/profile_form/widgets/profile_relay_quick_buttons.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:npt_flutter/constants.dart'; import 'package:npt_flutter/features/profile/profile.dart'; import 'package:npt_flutter/features/profile_form/widgets/profile_relay_at_sign_text_field.dart'; import 'package:npt_flutter/styles/sizes.dart'; +import 'package:npt_flutter/util/relay.dart'; import 'package:npt_flutter/widgets/custom_container.dart'; class ProfileRelayQuickButtons extends StatelessWidget { @@ -44,29 +44,29 @@ class ProfileRelayQuickButtons extends StatelessWidget { scrollDirection: Axis.horizontal, controller: controller, children: [ - ...Constants.defaultRelayOptions.entries.map( - (e) => Padding( - padding: const EdgeInsets.only(right: Sizes.p10), - child: CustomContainer.foreground( - key: Key(e.key), - child: SizedBox( - width: Sizes.p200, - height: Sizes.p50, - child: RadioListTile( - title: Text(e.value), - value: e.key, - groupValue: relayAtsign, - onChanged: (value) { - var bloc = context.read(); - bloc.add(ProfileEditEvent( - profile: (bloc.state as ProfileLoadedState).profile.copyWith(relayAtsign: value), - )); - }, + ...RelayUtil.getRelayDisplayNameMap(context).entries.map( + (e) => Padding( + padding: const EdgeInsets.only(right: Sizes.p10), + child: CustomContainer.foreground( + key: Key(e.key), + child: SizedBox( + width: Sizes.p200, + height: Sizes.p50, + child: RadioListTile( + title: Text(e.value), + value: e.key, + groupValue: relayAtsign, + onChanged: (value) { + var bloc = context.read(); + bloc.add(ProfileEditEvent( + profile: (bloc.state as ProfileLoadedState).profile.copyWith(relayAtsign: value), + )); + }, + ), + ), ), ), ), - ), - ), const ProfileRelayAtSignTextField(), ], ), diff --git a/packages/dart/npt_flutter/lib/features/settings/repository/settings_repository.dart b/packages/dart/npt_flutter/lib/features/settings/repository/settings_repository.dart index 9c6adfd1a..863f97f8e 100644 --- a/packages/dart/npt_flutter/lib/features/settings/repository/settings_repository.dart +++ b/packages/dart/npt_flutter/lib/features/settings/repository/settings_repository.dart @@ -6,11 +6,9 @@ import 'package:npt_flutter/features/settings/settings.dart'; class SettingsRepository { const SettingsRepository(); - AtKey get settingsAtKey => - AtKey.self('settings', namespace: Constants.namespace).build(); + AtKey get settingsAtKey => AtKey.self('settings', namespace: Constants.namespace).build(); - Settings get defaultSettings => Settings( - relayAtsign: Constants.defaultRelayOptions.values.first, + Settings get defaultSettings => const Settings( viewLayout: PreferredViewLayout.minimal, overrideRelay: false, ); @@ -18,8 +16,7 @@ class SettingsRepository { Future getSettings() async { AtClient atClient = AtClientManager.getInstance().atClient; try { - var value = await atClient - .get(settingsAtKey..sharedBy = atClient.getCurrentAtSign()); + var value = await atClient.get(settingsAtKey..sharedBy = atClient.getCurrentAtSign()); if (value.value == null) { // No settings saved, so use the defaults return defaultSettings; @@ -43,8 +40,7 @@ class SettingsRepository { Future deleteSettings(Settings settings) async { AtClient atClient = AtClientManager.getInstance().atClient; try { - return await atClient - .delete(settingsAtKey..sharedBy = atClient.getCurrentAtSign()); + return await atClient.delete(settingsAtKey..sharedBy = atClient.getCurrentAtSign()); } catch (_) { return false; } diff --git a/packages/dart/npt_flutter/lib/features/settings/widgets/settings_relay_quick_buttons.dart b/packages/dart/npt_flutter/lib/features/settings/widgets/settings_relay_quick_buttons.dart index 7c2b57bab..1888bfb47 100644 --- a/packages/dart/npt_flutter/lib/features/settings/widgets/settings_relay_quick_buttons.dart +++ b/packages/dart/npt_flutter/lib/features/settings/widgets/settings_relay_quick_buttons.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:npt_flutter/constants.dart'; import 'package:npt_flutter/features/settings/settings.dart'; +import 'package:npt_flutter/util/relay.dart'; import 'package:npt_flutter/widgets/custom_container.dart'; import '../../../styles/sizes.dart'; @@ -29,29 +29,29 @@ class SettingsRelayQuickButtons extends StatelessWidget { controller: controller, scrollDirection: Axis.horizontal, children: [ - ...Constants.defaultRelayOptions.entries.map( - (e) => Padding( - padding: const EdgeInsets.only(right: Sizes.p10), - child: CustomContainer.foreground( - key: Key(e.key), - child: SizedBox( - width: Sizes.p180, - child: RadioListTile( - title: Text(e.value), - value: e.key, - groupValue: relayAtsign, - onChanged: (value) { - var bloc = context.read(); - bloc.add(SettingsEditEvent( - settings: (bloc.state as SettingsLoadedState).settings.copyWith(relayAtsign: value), - save: true, - )); - }, + ...RelayUtil.getRelayDisplayNameMap(context).entries.map( + (e) => Padding( + padding: const EdgeInsets.only(right: Sizes.p10), + child: CustomContainer.foreground( + key: Key(e.key), + child: SizedBox( + width: Sizes.p180, + child: RadioListTile( + title: Text(e.value), + value: e.key, + groupValue: relayAtsign, + onChanged: (value) { + var bloc = context.read(); + bloc.add(SettingsEditEvent( + settings: (bloc.state as SettingsLoadedState).settings.copyWith(relayAtsign: value), + save: true, + )); + }, + ), + ), ), ), ), - ), - ), const SettingsRelayAtSignTextField(), ], ), diff --git a/packages/dart/npt_flutter/lib/localization/app_en.arb b/packages/dart/npt_flutter/lib/localization/app_en.arb index ca172fb49..0ca210b3e 100644 --- a/packages/dart/npt_flutter/lib/localization/app_en.arb +++ b/packages/dart/npt_flutter/lib/localization/app_en.arb @@ -53,6 +53,9 @@ "remotePort" : "Remote Port", "remotePortDescription" : "", "resetAtsign" : "Reset Atsign", + "rvAmDisplayName" : "Americas", + "rvApDisplayName" : "Asia-Pacific", + "rvEuDisplayName" : "Europe", "selectExportFile": "Please select a file to export to:", "serviceMapping" : "Service Mapping", "settings" : "Settings", @@ -76,4 +79,4 @@ "onboard" : "Onboard", "onboardingError" : "An error has occurred", "yaml" : "YAML" -} \ No newline at end of file +} diff --git a/packages/dart/npt_flutter/lib/util/relay.dart b/packages/dart/npt_flutter/lib/util/relay.dart new file mode 100644 index 000000000..4df31f2f9 --- /dev/null +++ b/packages/dart/npt_flutter/lib/util/relay.dart @@ -0,0 +1,17 @@ +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter/material.dart'; + +class RelayUtil { + static Map getRelayDisplayNameMap(BuildContext context) { + final strings = AppLocalizations.of(context)!; + return { + "@rv_am": strings.rvAmDisplayName, + "@rv_ap": strings.rvApDisplayName, + "@rv_eu": strings.rvEuDisplayName, + }; + } + + static List getRelayAtsignList() { + return ["@rv_am", "@rv_ap", "@rv_eu"]; + } +} diff --git a/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart b/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart index 478db0f35..432f4a0ef 100644 --- a/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart +++ b/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart @@ -170,7 +170,7 @@ class CustomTextButton extends StatelessWidget { Navigator.of(context) .pushAndRemoveUntil(MaterialPageRoute(builder: (context) => const LoadingPage()), (route) => false); await preSignout(); - Navigator.of(context).pushReplacementNamed(Routes.onboarding); + if (context.mounted) Navigator.of(context).pushReplacementNamed(Routes.onboarding); break; case CustomListTileType.selectRootDomain: await showDialog(