Skip to content

Commit

Permalink
Add nil check for country code and language code (flutter#4732)
Browse files Browse the repository at this point in the history
NSLocale objectForKey: may return nil for NSLocaleLanguageCode and
NSLocateCountryCode in certain cases.

This adds a defensive nil check for such cases.
  • Loading branch information
cbracken authored Mar 1, 2018
1 parent a4b1fcc commit 269bab7
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ - (void)onLocaleUpdated:(NSNotification*)notification {
NSLocale* currentLocale = [NSLocale currentLocale];
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
[_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]];
if (languageCode && countryCode)
[_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]];
}

#pragma mark - Set user settings
Expand Down

0 comments on commit 269bab7

Please sign in to comment.