load method
Start loading the resources for locale. The returned future completes
when the resources have finished loading.
It's assumed that this method will return an object that contains a collection of related string resources (typically defined with one method per resource). The object will be retrieved with Localizations.of.
Implementation
@override
Future<ShadLocalizationsData> load(Locale locale) {
// Two-pass: prefer exact language+country match, fall back to
// language-only, then to English.
final exact = ShadLocale.values.where((l) {
return l.languageCode == locale.languageCode &&
l.countryCode == locale.countryCode;
}).firstOrNull;
final match =
exact ??
ShadLocale.values
.where((l) => l.languageCode == locale.languageCode)
.firstOrNull ??
ShadLocale.en;
// English is the base locale (not deferred) — load synchronously so the
// widget tree is ready on the first frame, keeping tests fast.
if (match == ShadLocale.en) {
return SynchronousFuture<ShadLocalizationsData>(match.buildSync());
}
// All other locales are deferred imports. Must use the async build() so
// loadLibrary() is called before accessing the locale class (required on
// Flutter web / dart2js / wasm).
return match.build();
}