1717import io .flutter .FlutterInjector ;
1818import io .flutter .embedding .engine .FlutterEngine ;
1919import io .flutter .embedding .engine .dart .DartExecutor ;
20+ import io .flutter .embedding .engine .FlutterEngineGroup ;
2021import io .flutter .embedding .engine .plugins .FlutterPlugin ;
2122import io .flutter .plugin .common .BinaryMessenger ;
2223import io .flutter .plugin .common .EventChannel ;
@@ -50,6 +51,7 @@ public class FlutterIsolatePlugin implements FlutterPlugin, MethodCallHandler, S
5051 private Queue <IsolateHolder > queuedIsolates ;
5152 private Map <String , IsolateHolder > activeIsolates ;
5253 private Context context ;
54+ private FlutterEngineGroup engineGroup ;
5355
5456 private static void registerWithCustomRegistrant (io .flutter .embedding .engine .FlutterEngine flutterEngine ) {
5557 if (registrant == null ) return ;
@@ -94,6 +96,7 @@ public static void setCustomIsolateRegistrant(Class registrant) {
9496
9597 @ Override
9698 public void onAttachedToEngine (FlutterPluginBinding binding ) {
99+ engineGroup = new FlutterEngineGroup (binding .getApplicationContext ());
97100 setupChannel (binding .getBinaryMessenger (), binding .getApplicationContext ());
98101 }
99102
@@ -115,14 +118,13 @@ private void startNextIsolate() {
115118
116119 FlutterInjector .instance ().flutterLoader ().ensureInitializationComplete (context , null );
117120
118- isolate .engine = new FlutterEngine (context );
119-
120121 FlutterCallbackInformation cbInfo = FlutterCallbackInformation .lookupCallbackInformation (isolate .entryPoint );
121- FlutterRunArguments runArgs = new FlutterRunArguments ();
122122
123- runArgs .bundlePath = FlutterInjector .instance ().flutterLoader ().findAppBundlePath ();
124- runArgs .libraryPath = cbInfo .callbackLibraryPath ;
125- runArgs .entrypoint = cbInfo .callbackName ;
123+ isolate .engine = engineGroup .createAndRunEngine (context , new DartExecutor .DartEntrypoint (
124+ FlutterInjector .instance ().flutterLoader ().findAppBundlePath (),
125+ cbInfo .callbackLibraryPath ,
126+ cbInfo .callbackName
127+ ));
126128
127129 isolate .controlChannel = new MethodChannel (isolate .engine .getDartExecutor ().getBinaryMessenger (), NAMESPACE + "/control" );
128130 isolate .startupChannel = new EventChannel (isolate .engine .getDartExecutor ().getBinaryMessenger (), NAMESPACE + "/event" );
@@ -133,9 +135,6 @@ private void startNextIsolate() {
133135 if (registrant != null ) {
134136 registerWithCustomRegistrant (isolate .engine );
135137 }
136-
137- DartExecutor .DartCallback dartCallback = new DartExecutor .DartCallback (context .getAssets (), runArgs .bundlePath , cbInfo );
138- isolate .engine .getDartExecutor ().executeDartCallback (dartCallback );
139138 }
140139
141140 @ Override
0 commit comments