minor changes

This commit is contained in:
Sahil Kumar
2021-07-08 16:59:57 +05:30
parent 2691243102
commit ffb46ecdca
@@ -30,15 +30,15 @@ const kStreamChatSupportedLanguages = {'en'};
/// Generally speaking, this method is only intended to be used by /// Generally speaking, this method is only intended to be used by
/// [GlobalStreamChatLocalizations.delegate]. /// [GlobalStreamChatLocalizations.delegate].
GlobalStreamChatLocalizations? getStreamChatTranslation(Locale locale) { GlobalStreamChatLocalizations? getStreamChatTranslation(Locale locale) {
final languageCode = locale.languageCode;
assert(
kStreamChatSupportedLanguages.contains(languageCode),
'getStreamChatTranslation() called for unsupported locale "$locale"',
);
switch (locale.languageCode) { switch (locale.languageCode) {
case 'en': case 'en':
return const StreamChatLocalizationsEn(); return const StreamChatLocalizationsEn();
} }
assert(
false,
'getStreamChatTranslation() called for unsupported locale "$locale"',
);
return null;
} }
/// Implementation of localized strings for the stream chat widgets /// Implementation of localized strings for the stream chat widgets
@@ -85,7 +85,7 @@ abstract class GlobalStreamChatLocalizations
/// as the value of [MaterialApp.localizationsDelegates] to include /// as the value of [MaterialApp.localizationsDelegates] to include
/// the localizations for both the flutter and stream chat widget libraries. /// the localizations for both the flutter and stream chat widget libraries.
static const LocalizationsDelegate<StreamChatLocalizations> delegate = static const LocalizationsDelegate<StreamChatLocalizations> delegate =
_StreamChatLocalizationsDelegate(); _StreamChatLocalizationsDelegate();
/// A value for [MaterialApp.localizationsDelegates] that's typically used by /// A value for [MaterialApp.localizationsDelegates] that's typically used by
/// internationalized apps. /// internationalized apps.
@@ -127,17 +127,16 @@ class _StreamChatLocalizationsDelegate
kStreamChatSupportedLanguages.contains(locale.languageCode); kStreamChatSupportedLanguages.contains(locale.languageCode);
static final _loadedTranslations = static final _loadedTranslations =
<Locale, Future<StreamChatLocalizations>>{}; <Locale, Future<StreamChatLocalizations>>{};
@override @override
Future<StreamChatLocalizations> load(Locale locale) { Future<StreamChatLocalizations> load(Locale locale) {
assert(isSupported(locale), ''); assert(isSupported(locale), '');
return _loadedTranslations.putIfAbsent( return _loadedTranslations.putIfAbsent(
locale, locale,
() => () => SynchronousFuture<StreamChatLocalizations>(
SynchronousFuture<StreamChatLocalizations>( getStreamChatTranslation(locale)!,
getStreamChatTranslation(locale)!, ),
),
); );
} }