Skip to content

[Multiple Engine] FlutterEngineGroup.Options: support more parameters (like constructor) #107394

@Nayuta403

Description

@Nayuta403

Use case

Currently, FlutterEngine.spawn() can only pass a few arguments

  @NonNull
  /*package*/ FlutterEngine spawn(
      @NonNull Context context,
      @NonNull DartEntrypoint dartEntrypoint,
      @Nullable String initialRoute,
      @Nullable List<String> dartEntrypointArgs) {
    if (!isAttachedToJni()) {
      throw new IllegalStateException(
          "Spawn can only be called on a fully constructed FlutterEngine");
    }

    FlutterJNI newFlutterJNI =
        flutterJNI.spawn(
            dartEntrypoint.dartEntrypointFunctionName,
            dartEntrypoint.dartEntrypointLibrary,
            initialRoute,
            dartEntrypointArgs);
    return new FlutterEngine(
        context, // Context.
        null, // FlutterLoader. A null value passed here causes the constructor to get it from the
        // FlutterInjector.
        newFlutterJNI); // FlutterJNI.
  }

ref: https://github.com/flutter/engine/blob/2b5d5c3b2d7e8d8d8b57612c4dc85aea6743e088/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java#L392

Internally, it calls the constructor of FlutterEngine.

 public FlutterEngine(
      @NonNull Context context,
      @Nullable FlutterLoader flutterLoader,
      @NonNull FlutterJNI flutterJNI) {
    this(context, flutterLoader, flutterJNI, null, true);
  }
->
  public FlutterEngine(
      @NonNull Context context,
      @Nullable FlutterLoader flutterLoader,
      @NonNull FlutterJNI flutterJNI,
      @Nullable String[] dartVmArgs,
      boolean automaticallyRegisterPlugins) {
    this(
        context,
        flutterLoader,
        flutterJNI,
        new PlatformViewsController(),
        dartVmArgs,
        automaticallyRegisterPlugins);
  }
->
  public FlutterEngine(
      @NonNull Context context,
      @Nullable FlutterLoader flutterLoader,
      @NonNull FlutterJNI flutterJNI,
      @NonNull PlatformViewsController platformViewsController,
      @Nullable String[] dartVmArgs,
      boolean automaticallyRegisterPlugins) 
-> 
  public FlutterEngine(
      @NonNull Context context,
      @Nullable FlutterLoader flutterLoader,
      @NonNull FlutterJNI flutterJNI,
      @NonNull PlatformViewsController platformViewsController,
      @Nullable String[] dartVmArgs,
      boolean automaticallyRegisterPlugins,
      boolean waitForRestorationData)

Now I want to use the FlutterEngine.spawn, but at the same time I also hope to include more parameters (such as automaticallyRegisterPlugins). But I don't see a way to support that.

So can we extend more parameters to spawn, like the FlutterEngine constructor. (I can submit PR if you think it's ok)

Proposal

Flutterengine.spawn supports more parameters (like constructor)

      engine = new FlutterEngine(context);
      engine.spawn(context, dartEntrypoint, initialRoute, dartEntrypointArgs,/*automaticallyRegisterPlugins*/false);

also add in the FlutterEngineGroup.Options

  public static class Options {
    @NonNull private Context context;
    @Nullable private DartEntrypoint dartEntrypoint;
    @Nullable private String initialRoute;
    @Nullable private List<String> dartEntrypointArgs;
    //***ADD****//
    @Nullable boolean automaticallyRegisterPlugins;
    @Nullable PlatformViewsController platformViewsController;
    @Nullable boolean waitForRestorationData
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions