fittedFlag method

FittedBox fittedFlag(
  1. Widget? flag,
  2. String locCode,
  3. List lang
)

Wrap flag with required widgets.

also, here is logic for enum MultiLangCountries.

Implementation

FittedBox fittedFlag(Widget? flag, String locCode, List lang) {
  const flagError = Icon(Icons.error_outline_rounded);

  // Simple case - country with one language
  if (!multiLangForceAll && !countriesWithMulti.containsKey(locCode)) {
    return FittedBox(
      child: flag ?? flagError,
    );
  }

  // Country with many languages
  final language = locCode.split('_').first.toUpperCase();
  final country = lang.first.toLowerCase();
  final mlc = useNLettersInsteadOfIcon > 0
      ? MultiLangCountries.asBigLittle
      : multiLangCountries;

  final doubleFlag = (multiLangWidget != null)
      ? multiLangWidget!
      : (wTop, wDown, [double? radius, Key? key]) => MultiLangFlag(
            wTop: wTop,
            wDown: wDown,
            radius: radius,
          );

  return FittedBox(
    child: switch (mlc) {
      MultiLangCountries.auto when language == country =>
        flag ?? Text(language),
      MultiLangCountries.auto
          when language ==
              popularInCountry[country.toLowerCase()]?.toUpperCase() =>
        flag ?? Text(language),
      MultiLangCountries.auto when flag == null => doubleFlag(
          Text(language),
          Text(country),
          radius,
        ),
      MultiLangCountries.auto => doubleFlag(
          flag!,
          Text(language),
          radius,
        ),
      MultiLangCountries.flagWithSmallLang when flag != null => doubleFlag(
          flag,
          Text(language),
          radius,
        ),
      MultiLangCountries.flagWithSmallLang => Text(locCode),
      MultiLangCountries.langWithSmallFlag => doubleFlag(
          Text(language),
          flag ?? Text(country),
          radius,
        ),
      MultiLangCountries.asBigLittle when language.length >= 2 => doubleFlag(
          Text(language),
          Text(country),
          radius,
        ),
      MultiLangCountries.asBigLittle => Text(language),
      MultiLangCountries.onlyLanguage => Text(language),
      // TODO: Handle this case.
      MultiLangCountries.onlyFlag => FittedBox(
          child: Tooltip(
            message: toolTipPrefix + (localeNameFlag?.language ?? lang[1]),
            waitDuration: const Duration(milliseconds: 50),
            preferBelow: true,
            child: flag ?? flagError,
          ),
        ),
    },
  );
}