determineMessages method

HcUpgradeMessages determineMessages(
  1. BuildContext context
)

Determine which HcUpgradeMessages object to use. It will be either the one passed to HcUpgradeNewVersion, or one based on the app locale.

Implementation

HcUpgradeMessages determineMessages(BuildContext context) {
  {
    late HcUpgradeMessages appMessages;
    if (messages != null) {
      appMessages = messages!;
    } else {
      String? languageCode;
      try {
        // Get the current locale in the app.
        final locale = Localizations.localeOf(context);
        // Get the current language code in the app.
        languageCode = locale.languageCode;
        if (debugLogging) {
          if (kDebugMode) {
            print('hcUpgrade: current locale: $locale');
          }
        }
      } catch (e) {
        // ignored, really.
      }

      appMessages = HcUpgradeMessages(code: languageCode);
    }

    if (appMessages.languageCode.isEmpty) {
      if (kDebugMode) {
        print('hcUpgrade: error -> languageCode is empty');
      }
    } else if (debugLogging) {
      if (kDebugMode) {
        print('hcUpgrade: languageCode: ${appMessages.languageCode}');
      }
    }

    return appMessages;
  }
}