FlutterMain 的替代品是什么



我试图为后台服务启动回调的代码。

public class PushService extends JobIntentService implements MethodCallHandler {
private static FlutterEngine backgroundFlutterEngine = null;
private void startPushService(Context context) {
synchronized (serviceStarted) {
if (backgroundFlutterEngine == null) {
final Long callbackHandle = PushStore.getInstance().getPreferenceLongValue(
PushPlugin.CALLBACK_DISPATCHER_ID, 0L);
if (callbackHandle == 0L) {
Log.e(TAG, "Fatal: no callback registered.");
return;
}
final FlutterCallbackInformation callbackInfo =
FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
if (callbackInfo == null) {
Log.e(TAG, "Fatal: failed to find callback info.");
return;
}
Log.i(TAG, "Starting PushService...");
backgroundFlutterEngine = new FlutterEngine(context);
DartCallback args = DartCallback(context.getAssets(), FlutterMain.findAppBundlePath(context), callbackInfo);
backgroundFlutterEngine.getDartExecutor().executeDartCallback(args);
...
}
}
}
}

但是FlutterMain被弃用了,如何用新的方式执行dart回调?

据我所知,FlutterMain已被FlutterLoader取代。

编辑:在FlutterMain文档页面上,就在第一个水平分隔器的正下方,它提到了这种替换。

最新更新