of static method
Retrieves the appropriate CallKitClientLocalizations instance.
This method provides a convenient way to get localizations with intelligent fallback logic:
- If DefaultLanguage is set to Chinese, returns Chinese localizations
- If DefaultLanguage is set to English, returns English localizations
- If
contextis provided, attempts to get localizations from the widget tree - Falls back to system locale or defaults to English
The context parameter is optional. If provided, the method will attempt
to retrieve localizations from the widget tree first.
Returns a CallKitClientLocalizations instance, never null (defaults to English if all other methods fail).
Example:
// With context
final localizations = S.of(context);
// Without context (uses default language or system locale)
final localizations = S.of();
Implementation
static CallKitClientLocalizations of([BuildContext? context]) {
CallKitClientLocalizations? localizations;
if (DefaultLanguage.defaultLanguage == languageZh) {
return CallKitClientLocalizationsZh();
}
if (DefaultLanguage.defaultLanguage == languageEn) {
return CallKitClientLocalizationsEn();
}
if (context != null) {
localizations = CallKitClientLocalizations.of(context);
}
if (localizations == null) {
var local = PlatformDispatcher.instance.locale;
try {
localizations = lookupCallKitClientLocalizations(local);
} catch (e) {
localizations = CallKitClientLocalizationsEn();
}
}
return localizations;
}