updateCurrency method

Future<void> updateCurrency(
  1. OsmLocation location,
  2. PriceModel model
)

Implementation

Future<void> updateCurrency(OsmLocation location, PriceModel model) async {
  model.location = location;
  if (location.countryCode == null) {
    return;
  }
  final Currency? newCurrency = OpenFoodFactsCountry.fromOffTag(
    location.countryCode,
  )?.currency;

  if (newCurrency != null && model.currency != newCurrency) {
    final AppLocalizations appLocalizations = AppLocalizations.of(context);
    final SmoothColorsThemeExtension extension = context
        .extension<SmoothColorsThemeExtension>();

    final Currency? currency = await showSmoothAlertModalSheet<Currency?>(
      context: context,
      title: appLocalizations.prices_currency_change_proposal_title,
      message: TextWithBoldParts(
        text: appLocalizations.prices_currency_change_proposal_message(
          model.currency.name,
          newCurrency.name,
        ),
        textStyle: Theme.of(
          context,
        ).textTheme.bodyLarge?.copyWith(fontWeight: FontWeight.w500),
      ),
      actionLabels: <String>[
        appLocalizations.prices_currency_change_proposal_action_approve(
          newCurrency.name,
        ),
        appLocalizations.prices_currency_change_proposal_action_cancel(
          model.currency.name,
        ),
      ],
      actionIcons: <Widget>[
        Icon(Icons.check_circle_rounded, color: extension.success),
        Icon(Icons.cancel_rounded, color: extension.error),
      ],
      actionValues: <Currency?>[newCurrency, null],
    );

    if (currency != null) {
      model.currency = currency;
    }
  }
}