-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The getter 'languageCode' was called on null flutter for iOS #39032
Comments
@prudnikoff |
@nickrivers |
I am getting the following on my test device an iPhone 7 iOS 13.1.2, running a production build based on the flutter stable branch : NoSuchMethodError: The getter 'languageCode' was called on null. When I:
This only happens on physical iOS devices running a production build. Can’t test on a physical iOS device in debug mode on stable at the moment. If I shutdown my app app and reopen it the error still occurs, I have to uninstall the app or power off the device to get my app working again. This wasn't happening when the app was built using older versions of flutter stable, unfortunately I didn't notice at which version of flutter stable it started happening. flutter doctor -v [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 11.1) [✓] Android Studio (version 3.5) [✓] VS Code (version 1.39.1) [!] Connected device ! Doctor found issues in 1 category. |
Same problem here. When I deploy the app to the pychical device it is hapennig. |
Same for me also running in debug mode on iOS Emulator, ios 13.3. |
Maybe a related problem is that WidgetsFlutterBinding.ensureInitialized();
final locale = window.locale;
Intl.systemLocale = locale.toString(); Works fine on Android, causes random crash on iOS (device). |
Workaround to my issue: WidgetsFlutterBinding.ensureInitialized();
while (window.locale == null) {
await Future.delayed(const Duration(milliseconds: 1));
}
final locale = window.locale;
Intl.systemLocale = locale.toString(); Not pretty but it works... |
Issue still persists in 2020 |
Hello, Currently I removed the localeResolutionCallback, but in future i'll have some problems with it.
|
@GaryQian do you know what's going on here? I remember you doing some work on locales on iOS, I think. |
I will look into it! |
One thing that looks fishy to me - in FlutterViewController.mm, we're not calling the flow to update the locales until |
This issue means that localized Flutter apps may be initially rendered with the wrong locale and (usually but not always) re-drawn later with the correct one. This is tremendously problematic for things like dialogs and screens pushed on launch that can end up "capturing" the wrong locale. I can't believe that this problem isn't more widely noticed. |
I have a fix for this. Working on writing a test for it. |
For people looking for a workaround, copying what I wrote on a similar bug: The patch for this may take some time before it rolls on to a usable channel for people experiencing this bug. For now, this can be worked around by using a platform channel when on iOS to request the current locale from the device, as explained here: https://flutter.dev/docs/development/platform-integration/platform-channels#step-4-add-an-ios-platform-specific-implementation Alternatively, you could draw a splash screen or animation until the locale initializes (and you can check that properly by adding an observer to the WidgetsBinding that overrides Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
if (WidgetsBinding.instance.window.locale == null) {
Completer<Locale> completer = Completer<Locale>();
WidgetsBinding.instance.addObserver(LocaleObserver(completer));
// completer.future is now a `Future` that will complete when the locale is available.
}
}
class LocaleObserver extends WidgetsBindingObserver {
LocaleObserver(this.completer);
final Completer<Locale> completer;
@override
void didChangeLocale(List<Locale> locale) {
WidgetsBinding.instance.removeObserver(this);
completer.complete(WidgetsBinding.instance.window.locale);
}
} |
Even better work around: Add this to your AppDelegate.swift: @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
// Work-around for https://github.com/flutter/flutter/issues/39032
// This is safe to remove once the fix for that is available in the SDK
// used by this application.
guard let controller = window?.rootViewController as? FlutterViewController else {
fatalError("rootViewController is not type FlutterViewController")
}
let engine = controller.engine!
let currentLocale = NSLocale.current
if (currentLocale.languageCode != nil) {
engine.localizationChannel?.invokeMethod("setLocale", arguments: [currentLocale.languageCode!, currentLocale.regionCode ?? "", currentLocale.scriptCode ?? "", currentLocale.variantCode ?? ""])
} |
Will this correction be released soon to any branch? |
It's in 1.17.5 dev and in all the 1.18.x series. |
Switching channels to dev seemed to have fixed issue for us. |
This issue is still not solved for 1.20. |
Any fix for this yet? |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Hello!
Still have the error with localization for Flutter iOS application (for Android everything works fine).
My code for App widget:
The point is that when I try to launch it with some breakpoints, everything works good and
locale
is not null. But when I try the same without any breakpoints, I have error insidelocaleResolutionCallback
- The getter 'languageCode' was called on null. Tried several times some tips about this issue for iOS:for Info.plst
2) Added locales support for iOS project.
But nothing helped.
Don't know what to do. Localization is very important, I thing, but it's so ugly for Flutter now.
The text was updated successfully, but these errors were encountered: