Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Apr 2, 2020

Right now, FlutterViewController listens for updates to the system locale and initializes dart:ui#window.locale at viewDidAppear. This is too late for callers who want to know the locale in main (or, when they're trying to set up localization for a WidgetsApp or derivative).

This patch makes FlutterEngine responsible for setting the Locale and listening for changes, and makes sure that happens earlier in the initialization cycle.

Adding the assertion to main.dart of the Scenarios app makes tests fail if the locale is not set up, with a log like this:

00:54:37.155 Scenarios[31421:31950323] <XCTWaiter: 0x600001324ef0, state: XCTWaiterStateInProgress> entering wait loop for 30.00s with expectations: `firstFrameRendered` AND `Expect value of 'displayingFlutterUI' of <FlutterViewController: 0x7fbaa9841800> to be '1'`
2020-04-02 00:54:37.400555-0700 Scenarios[31421:31950908] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: 'package:scenario_app/main.dart': Failed assertion: line 46 pos 10: 'window.locale != null': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:38:5)
#2      main (package:scenario_app/main.dart:46:10)
#3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:241:25)
#4      _rootRun (dart:async/zone.dart:1184:13)
#5      _CustomZone.run (dart:async/zone.dart:1077:19)
#6      _runZoned (dart:async/zone.dart:1619:10)
#7      runZonedGuarded (dart:async/zone.dart:1608:12)
#8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:233:5)
#9      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Fixes flutter/flutter#39032

@dnfield dnfield marked this pull request as ready for review April 2, 2020 07:56
@auto-assign auto-assign bot requested a review from flar April 2, 2020 07:56
[_engine.get() platformViewsController] -> SetFlutterView(_flutterView.get());
[_engine.get() platformViewsController] -> SetFlutterViewController(self);
[_engine.get() platformView] -> NotifyCreated();
[_engine.get() platformViewsController]->SetFlutterView(_flutterView.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this stuff because the newest toolchain brought a new clang-format along with it? If possible, can you submit this without this bit. Lets format the repo again so PRs are not polluted with these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. Without this, the format ci job fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My formatter always clobbered these, nice to have CI in alignment with my tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to pull these out again because the toolchain roll got reverted. When I land it again, I'll land a full reformat with or after it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The getter 'languageCode' was called on null flutter for iOS

4 participants