1111import io .flutter .FlutterInjector ;
1212import io .flutter .embedding .engine .dart .DartExecutor .DartEntrypoint ;
1313import io .flutter .embedding .engine .loader .FlutterLoader ;
14+ import io .flutter .plugin .platform .PlatformViewsController ;
1415import java .util .ArrayList ;
1516import java .util .List ;
1617
@@ -142,20 +143,39 @@ public FlutterEngine createAndRunEngine(@NonNull Options options) {
142143 DartEntrypoint dartEntrypoint = options .getDartEntrypoint ();
143144 String initialRoute = options .getInitialRoute ();
144145 List <String > dartEntrypointArgs = options .getDartEntrypointArgs ();
146+ PlatformViewsController platformViewsController = options .getPlatformViewsController ();
147+ platformViewsController =
148+ platformViewsController != null ? platformViewsController : new PlatformViewsController ();
149+ boolean automaticallyRegisterPlugins = options .getAutomaticallyRegisterPlugins ();
150+ boolean waitForRestorationData = options .getWaitForRestorationData ();
145151
146152 if (dartEntrypoint == null ) {
147153 dartEntrypoint = DartEntrypoint .createDefault ();
148154 }
149155
150156 if (activeEngines .size () == 0 ) {
151- engine = createEngine (context );
157+ engine =
158+ createEngine (
159+ context ,
160+ platformViewsController ,
161+ automaticallyRegisterPlugins ,
162+ waitForRestorationData );
152163 if (initialRoute != null ) {
153164 engine .getNavigationChannel ().setInitialRoute (initialRoute );
154165 }
155166 engine .getDartExecutor ().executeDartEntrypoint (dartEntrypoint , dartEntrypointArgs );
156167 } else {
157168 engine =
158- activeEngines .get (0 ).spawn (context , dartEntrypoint , initialRoute , dartEntrypointArgs );
169+ activeEngines
170+ .get (0 )
171+ .spawn (
172+ context ,
173+ dartEntrypoint ,
174+ initialRoute ,
175+ dartEntrypointArgs ,
176+ platformViewsController ,
177+ automaticallyRegisterPlugins ,
178+ waitForRestorationData );
159179 }
160180
161181 activeEngines .add (engine );
@@ -178,8 +198,19 @@ public void onEngineWillDestroy() {
178198 }
179199
180200 @ VisibleForTesting
181- /* package */ FlutterEngine createEngine (Context context ) {
182- return new FlutterEngine (context );
201+ /* package */ FlutterEngine createEngine (
202+ Context context ,
203+ @ NonNull PlatformViewsController platformViewsController ,
204+ boolean automaticallyRegisterPlugins ,
205+ boolean waitForRestorationData ) {
206+ return new FlutterEngine (
207+ context , // Context.
208+ null , // FlutterLoader.
209+ null , // FlutterJNI.
210+ platformViewsController , // PlatformViewsController.
211+ null , // String[]. The Dart VM has already started, this arguments will have no effect.
212+ automaticallyRegisterPlugins , // boolean.
213+ waitForRestorationData ); // boolean.
183214 }
184215
185216 /** Options that control how a FlutterEngine should be created. */
@@ -188,6 +219,9 @@ public static class Options {
188219 @ Nullable private DartEntrypoint dartEntrypoint ;
189220 @ Nullable private String initialRoute ;
190221 @ Nullable private List <String > dartEntrypointArgs ;
222+ @ NonNull private PlatformViewsController platformViewsController ;
223+ private boolean automaticallyRegisterPlugins = true ;
224+ private boolean waitForRestorationData = false ;
191225
192226 public Options (@ NonNull Context context ) {
193227 this .context = context ;
@@ -219,6 +253,28 @@ public List<String> getDartEntrypointArgs() {
219253 return dartEntrypointArgs ;
220254 }
221255
256+ /** Manages platform views. */
257+ public PlatformViewsController getPlatformViewsController () {
258+ return platformViewsController ;
259+ }
260+
261+ /**
262+ * If plugins are automatically registered, then they are registered during the {@link
263+ * io.flutter.embedding.engine.FlutterEngine}'s constructor.
264+ */
265+ public boolean getAutomaticallyRegisterPlugins () {
266+ return automaticallyRegisterPlugins ;
267+ }
268+
269+ /**
270+ * The waitForRestorationData flag controls whether the engine delays responding to requests
271+ * from the framework for restoration data until that data has been provided to the engine via
272+ * {@code RestorationChannel.setRestorationData(byte[] data)}.
273+ */
274+ public boolean getWaitForRestorationData () {
275+ return waitForRestorationData ;
276+ }
277+
222278 /**
223279 * Setter for `dartEntrypoint` property.
224280 *
@@ -251,5 +307,41 @@ public Options setDartEntrypointArgs(List<String> dartEntrypointArgs) {
251307 this .dartEntrypointArgs = dartEntrypointArgs ;
252308 return this ;
253309 }
310+
311+ /**
312+ * Setter for `platformViewsController` property.
313+ *
314+ * @param platformViewsController Manages platform views.
315+ */
316+ public Options setPlatformViewsController (
317+ @ NonNull PlatformViewsController platformViewsController ) {
318+ this .platformViewsController = platformViewsController ;
319+ return this ;
320+ }
321+
322+ /**
323+ * Setter for `automaticallyRegisterPlugins` property.
324+ *
325+ * @param automaticallyRegisterPlugins If plugins are automatically registered, then they are
326+ * registered during the execution of {@link io.flutter.embedding.engine.FlutterEngine}'s
327+ * constructor.
328+ */
329+ public Options setAutomaticallyRegisterPlugins (boolean automaticallyRegisterPlugins ) {
330+ this .automaticallyRegisterPlugins = automaticallyRegisterPlugins ;
331+ return this ;
332+ }
333+
334+ /**
335+ * Setter for `waitForRestorationData` property.
336+ *
337+ * @param waitForRestorationData The waitForRestorationData flag controls whether the engine
338+ * delays responding to requests from the framework for restoration data until that data has
339+ * been provided to the engine via {@code RestorationChannel.setRestorationData(byte[]
340+ * data)}.
341+ */
342+ public Options setWaitForRestorationData (boolean waitForRestorationData ) {
343+ this .waitForRestorationData = waitForRestorationData ;
344+ return this ;
345+ }
254346 }
255347}
0 commit comments