mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR adds FlutterViewController.id, and formalizes how FlutterViewController is initialized by FlutterEngine: When FlutterViewController is set to the engine, the engine calls FlutterViewController#attachToEngine:withId:. When FlutterViewController is unset from the engine, the engine calls FlutterViewController#detachFromEngine. This allows the ID to be generated by the engine. The default View ID is now 1 instead of 0. In this way, we can use 0 as an empty value, the value for FlutterViewController.id when the FVC is not attached to an engine. (IDs are meant to be opaque, and views should be a map, not an array anyway.) This PR moves almost all initialization code into FVC's CommonInit to ensure that all init path produces the expected result. With this PR, FlutterEngine no long supports replacing viewController (from non-null to a different non-null). Setting the view controller (from null to non-null) is intended to allow pre-warming an engine before displaying it in add-to-app, but replacing the view controller does not make much sense. If the developer wants to persist the state of the view between different windows, they could just attach the view controller to different windows. In fact, Flutter doesn't even have a way to create a FlutterViewController that is unattached to an engine. All initializers either require an engine or create an engine. As a result, unit tests that used to create FVC with the wrong initializer are fixed.
[macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing (flutter/engine#38981)
Description
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
androidapp-frameworkcross-platformdartdart-platformdesktopflutterflutter-packagefuchsiaioslinux-desktopmacosmaterial-designmobilemobile-developmentskiawebweb-frameworkwindows
2.5 GiB
Languages
Dart
75%
C++
16.5%
Objective-C++
2.9%
Java
2.8%
Objective-C
0.7%
Other
1.9%