Skip to content

Commit 441a96b

Browse files
committed
Migrate to nullsafety
1 parent ebd5fec commit 441a96b

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

as2f/src/main/resources/dart_i18n.mvel

+20-18
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
2727
];
2828
}
2929

30-
LocaleListResolutionCallback listResolution({Locale fallback}) {
31-
return (List<Locale> locales, Iterable<Locale> supported) {
30+
LocaleListResolutionCallback listResolution({Locale? fallback}) {
31+
return (List<Locale>? locales, Iterable<Locale> supported) {
3232
if (locales == null || locales.isEmpty) {
3333
return fallback ?? supported.first;
3434
} else {
@@ -37,51 +37,53 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
3737
};
3838
}
3939

40-
LocaleResolutionCallback resolution({Locale fallback}) {
41-
return (Locale locale, Iterable<Locale> supported) {
40+
LocaleResolutionCallback resolution({Locale? fallback}) {
41+
return (Locale? locale, Iterable<Locale> supported) {
4242
return _resolve(locale, fallback, supported);
4343
};
4444
}
4545

46-
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported) {
46+
Locale _resolve(Locale? locale, Locale? fallback, Iterable<Locale> supported) {
4747
if (locale == null || !isSupported(locale)) {
4848
return fallback ?? supported.first;
4949
}
5050

5151
final Locale languageLocale = Locale(locale.languageCode, "");
5252
if (supported.contains(locale)) {
5353
return locale;
54-
} else if (supported.contains(languageLocale)) {
54+
} else if (supported!.contains(languageLocale)) {
5555
return languageLocale;
5656
} else {
57-
final Locale fallbackLocale = fallback ?? supported.first;
57+
final Locale fallbackLocale = fallback ?? supported!.first;
5858
return fallbackLocale;
5959
}
6060
}
6161

6262
@override
63-
Future<S> load(Locale locale) {
64-
final String lang = getLang(locale);
63+
Future<S> load(Locale? locale) {
64+
final String? lang = getLang(locale);
6565
if (lang != null) {
6666
switch (lang) {
67-
@foreach{locale : locales} case "@{locale.value}": return SynchronousFuture<S>(const @{'$'}@{locale.value}());@end{'\n'}
67+
case "en":
68+
return SynchronousFuture<S>(const $en());
69+
case "de":
70+
return SynchronousFuture<S>(const $de());
6871
default:
69-
// NO-OP.
72+
// NO-OP.
7073
}
7174
}
7275
return SynchronousFuture<S>(const S());
7376
}
7477

7578
@override
76-
bool isSupported(Locale locale) =>
77-
locale != null && supportedLocales.contains(locale);
79+
bool isSupported(Locale? locale) => locale != null && supportedLocales.contains(locale);
7880

7981
@override
8082
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
8183
}
8284

83-
String getLang(Locale l) => l == null
84-
? null
85-
: l.countryCode != null && l.countryCode.isEmpty
86-
? l.languageCode
87-
: l.toString();
85+
String? getLang(Locale? l) => l == null
86+
? null
87+
: l.countryCode != null && l.countryCode!.isEmpty
88+
? l.languageCode
89+
: l.toString();

as2f/src/main/resources/dart_i18n_class.mvel

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class S implements WidgetsLocalizations {
55
static const GeneratedLocalizationsDelegate delegate =
66
GeneratedLocalizationsDelegate();
77

8-
static S of(BuildContext context) => Localizations.of<S>(context, S);
8+
static S of(BuildContext context) => Localizations.of<S>(context, S) ?? S();
99

1010
@override
1111
TextDirection get textDirection => TextDirection.@{textDirection.value};

as2f/src/main/resources/dart_i18n_quantity.mvel

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
String @{key}(@{emitArgs()}) {
22
plural_rules.startRuleEvaluation(quantity);
3-
final pluralCase = plural_rules.pluralRules["@{locale}"]() as plural_rules.PluralCase;
4-
switch (pluralCase) {
3+
4+
final pluralRulesLocale = plural_rules.pluralRules["@{locale}"];
5+
if (pluralRulesLocale == null) return "";
6+
7+
switch (pluralRulesLocale()) {
58
@foreach{item : items} case plural_rules.PluralCase.@{item.quantity.value}: return "@{item.value}";@end{'\n'}
69
default: return "";
710
}

0 commit comments

Comments
 (0)