Skip to content

Ability to send structured data to Flutter app at startup when using FlutterEngineGroup #91547

@ColdPaleLight

Description

@ColdPaleLight

FlutterEngineGroup already supports initialRoute, but in the add to app scenario, structured arguments transfer is also very necessary for users.

design doc: https://docs.google.com/document/d/1ufsbXdhCm1qTAY2eXsRrVrfxED5WCZgqQ-Tm2LzScoE/edit

I want to add a new parameter named initialArguments to pass the startup arguments from platform to Flutter app.
Usage may look like this:
Android:

Map initialArguments = new HashMap();
intialArguments.put("color", "yellow");
List<String> dartEntrypointArgs = convertToDartEntrypointArgs(intialArguments);
FlutterEngine engine = engineGroup.createAndRunEngine(activity, dartEntrypoint, initialRoute, dartEntrypointArgs);

iOS:

NSDictionary *initialArguments = @{@"color" : @"yellow"};
NSArray *entrypointArgs = convertToDartEntrypointArgs(initialArguments);
FlutterEngine *engine = [engineGroup makeEngineWithEntrypoint:entrypoint
                                           libraryURI:libraryURI
                                          initialRoute:initialRoute
                                          entrypointArgs:entrypointArgs];

Dart

void main(List<String> rawArgs) {
  dynamic arguments = convertEntrypointArgsToMap(rawArgs);
  String color = arguments['color'];
  ......
}

Related Issue

This Issue is similar to the following two, but focuses more on FlutterEngineGroup
#23786
#34170

When there is no FlutterEngineGroup, initialArguments can also be passed to the Flutter app in the following way

Android

engine.getDartExecutor().executeDartEntrypoint(dartEntrypoint, dartEntrypointArgs);

iOS

[engine runWithEntrypoint:entrypoint
                   libraryURI:libraryURI
                 initialRoute:initialRoute
            entrypointArgs:entrypointArgs];

/cc @gaaclarke @xster
Any thoughts about this?

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: existing-appsIntegration with existing apps via the add-to-app flowc: new featureNothing broken; request for a new capabilitycustomer: alibabaengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyplatform-iosiOS 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