Skip to content

Migrate to null-safety #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions as2f/src/main/resources/dart_i18n.mvel
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
];
}

LocaleListResolutionCallback listResolution({Locale fallback}) {
return (List<Locale> locales, Iterable<Locale> supported) {
LocaleListResolutionCallback listResolution({Locale? fallback}) {
return (List<Locale>? locales, Iterable<Locale> supported) {
if (locales == null || locales.isEmpty) {
return fallback ?? supported.first;
} else {
Expand All @@ -37,13 +37,13 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
};
}

LocaleResolutionCallback resolution({Locale fallback}) {
return (Locale locale, Iterable<Locale> supported) {
LocaleResolutionCallback resolution({Locale? fallback}) {
return (Locale? locale, Iterable<Locale> supported) {
return _resolve(locale, fallback, supported);
};
}

Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported) {
Locale _resolve(Locale? locale, Locale? fallback, Iterable<Locale> supported) {
if (locale == null || !isSupported(locale)) {
return fallback ?? supported.first;
}
Expand All @@ -60,28 +60,30 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}

@override
Future<S> load(Locale locale) {
final String lang = getLang(locale);
Future<S> load(Locale? locale) {
final String? lang = getLang(locale);
if (lang != null) {
switch (lang) {
@foreach{locale : locales} case "@{locale.value}": return SynchronousFuture<S>(const @{'$'}@{locale.value}());@end{'\n'}
case "en":
return SynchronousFuture<S>(const $en());
case "de":
return SynchronousFuture<S>(const $de());
default:
// NO-OP.
// NO-OP.
}
}
return SynchronousFuture<S>(const S());
}

@override
bool isSupported(Locale locale) =>
locale != null && supportedLocales.contains(locale);
bool isSupported(Locale? locale) => locale != null && supportedLocales.contains(locale);

@override
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
}

String getLang(Locale l) => l == null
? null
: l.countryCode != null && l.countryCode.isEmpty
? l.languageCode
: l.toString();
String? getLang(Locale? l) => l == null
? null
: l.countryCode != null && l.countryCode!.isEmpty
? l.languageCode
: l.toString();
2 changes: 1 addition & 1 deletion as2f/src/main/resources/dart_i18n_class.mvel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class S implements WidgetsLocalizations {
static const GeneratedLocalizationsDelegate delegate =
GeneratedLocalizationsDelegate();

static S of(BuildContext context) => Localizations.of<S>(context, S);
static S of(BuildContext context) => Localizations.of<S>(context, S) ?? S();

@override
TextDirection get textDirection => TextDirection.@{textDirection.value};
Expand Down
7 changes: 5 additions & 2 deletions as2f/src/main/resources/dart_i18n_quantity.mvel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
String @{key}(@{emitArgs()}) {
plural_rules.startRuleEvaluation(quantity);
final pluralCase = plural_rules.pluralRules["@{locale}"]() as plural_rules.PluralCase;
switch (pluralCase) {

final pluralRulesLocale = plural_rules.pluralRules["@{locale}"];
if (pluralRulesLocale == null) return "";

switch (pluralRulesLocale()) {
@foreach{item : items} case plural_rules.PluralCase.@{item.quantity.value}: return "@{item.value}";@end{'\n'}
default: return "";
}
Expand Down