Files
sendico/frontend/pweb/lib/utils/flagged_locale.dart
2025-11-13 15:06:15 +03:00

56 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:country_flags/country_flags.dart';
String _locale2Flag(Locale l) {
if (l.languageCode == 'en') {
return 'gb';
}
if (l.languageCode == 'uk') {
return 'ua';
}
if (l.languageCode == 'el') {
return 'gr';
}
return l.languageCode;
}
final Map<String, String> localeNames = {
'en': 'English',
'es': 'Español',
'fr': 'Français',
'de': 'Deutsch',
'uk': 'Українська',
'el': 'Ελληνικά',
'ru': 'Русский',
'pt': 'Português',
'pl': 'Polski',
'it': 'Italiano',
'nl': 'Nederlands',
};
Widget getCountryFlag(Locale locale) {
return
CountryFlag.fromCountryCode(
_locale2Flag(locale),
height: 24,
width: 30,
shape: Rectangle(),
);
}
String getLocaleName(Locale locale) {
return localeNames[locale.languageCode] ?? Intl.canonicalizedLocale(locale.toString()).toUpperCase();
}
Widget getFlaggedLocale(Locale locale) {
return ListTile(
leading: getCountryFlag(locale),
title: Text(getLocaleName(locale), overflow: TextOverflow.ellipsis),
);
}