@@ -90,6 +90,7 @@ public interface DelegateFactory {
90
90
private boolean isFirstFrameRendered ;
91
91
private boolean isAttached ;
92
92
private Integer previousVisibility ;
93
+ @ Nullable private FlutterEngineGroup engineGroup ;
93
94
94
95
@ NonNull
95
96
private final FlutterUiDisplayListener flutterUiDisplayListener =
@@ -109,8 +110,13 @@ public void onFlutterUiNoLongerDisplayed() {
109
110
};
110
111
111
112
FlutterActivityAndFragmentDelegate (@ NonNull Host host ) {
113
+ this (host , null );
114
+ }
115
+
116
+ FlutterActivityAndFragmentDelegate (@ NonNull Host host , @ Nullable FlutterEngineGroup engineGroup ) {
112
117
this .host = host ;
113
118
this .isFirstFrameRendered = false ;
119
+ this .engineGroup = engineGroup ;
114
120
}
115
121
116
122
/**
@@ -220,6 +226,21 @@ void onAttach(@NonNull Context context) {
220
226
return activity ;
221
227
}
222
228
229
+ private FlutterEngineGroup .Options addEntrypointOptions (FlutterEngineGroup .Options options ) {
230
+ String appBundlePathOverride = host .getAppBundlePath ();
231
+ if (appBundlePathOverride == null || appBundlePathOverride .isEmpty ()) {
232
+ appBundlePathOverride = FlutterInjector .instance ().flutterLoader ().findAppBundlePath ();
233
+ }
234
+
235
+ DartExecutor .DartEntrypoint dartEntrypoint =
236
+ new DartExecutor .DartEntrypoint (
237
+ appBundlePathOverride , host .getDartEntrypointFunctionName ());
238
+ return options
239
+ .setDartEntrypoint (dartEntrypoint )
240
+ .setInitialRoute (host .getInitialRoute ())
241
+ .setDartEntrypointArgs (host .getDartEntrypointArgs ());
242
+ }
243
+
223
244
/**
224
245
* Obtains a reference to a FlutterEngine to back this delegate and its {@code host}.
225
246
*
@@ -277,17 +298,9 @@ void onAttach(@NonNull Context context) {
277
298
+ "'" );
278
299
}
279
300
280
- String appBundlePathOverride = host .getAppBundlePath ();
281
- if (appBundlePathOverride == null || appBundlePathOverride .isEmpty ()) {
282
- appBundlePathOverride = FlutterInjector .instance ().flutterLoader ().findAppBundlePath ();
283
- }
284
-
285
- DartExecutor .DartEntrypoint dartEntrypoint =
286
- new DartExecutor .DartEntrypoint (
287
- appBundlePathOverride , host .getDartEntrypointFunctionName ());
288
301
flutterEngine =
289
302
flutterEngineGroup .createAndRunEngine (
290
- host . getContext (), dartEntrypoint , host .getInitialRoute ( ));
303
+ addEntrypointOptions ( new FlutterEngineGroup . Options ( host .getContext ()) ));
291
304
isFlutterEngineFromHost = false ;
292
305
return ;
293
306
}
@@ -298,12 +311,17 @@ void onAttach(@NonNull Context context) {
298
311
TAG ,
299
312
"No preferred FlutterEngine was provided. Creating a new FlutterEngine for"
300
313
+ " this FlutterFragment." );
314
+
315
+ FlutterEngineGroup group =
316
+ engineGroup == null
317
+ ? new FlutterEngineGroup (host .getContext (), host .getFlutterShellArgs ().toArray ())
318
+ : engineGroup ;
301
319
flutterEngine =
302
- new FlutterEngine (
303
- host . getContext (),
304
- host . getFlutterShellArgs (). toArray (),
305
- /*automaticallyRegisterPlugins=*/ false ,
306
- /*willProvideRestorationData=*/ host .shouldRestoreAndSaveState ());
320
+ group . createAndRunEngine (
321
+ addEntrypointOptions (
322
+ new FlutterEngineGroup . Options ( host . getContext ())
323
+ . setAutomaticallyRegisterPlugins ( false )
324
+ . setWaitForRestorationData ( host .shouldRestoreAndSaveState ()) ));
307
325
isFlutterEngineFromHost = false ;
308
326
}
309
327
0 commit comments