5package io.flutter.embedding.engine.systemchannels;
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import androidx.annotation.VisibleForTesting;
10import io.flutter.FlutterInjector;
12import io.flutter.embedding.engine.dart.DartExecutor;
13import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
14import io.flutter.plugin.common.MethodCall;
15import io.flutter.plugin.common.MethodChannel;
16import io.flutter.plugin.common.StandardMethodCodec;
17import java.util.ArrayList;
18import java.util.HashMap;
29 private static final String TAG =
"DeferredComponentChannel";
31 @NonNull
private final MethodChannel channel;
32 @Nullable
private DeferredComponentManager deferredComponentManager;
36 @NonNull
private Map<String,
List<MethodChannel.Result>> componentNameToResults;
38 @NonNull @VisibleForTesting
40 new MethodChannel.MethodCallHandler() {
42 public void onMethodCall(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
43 if (deferredComponentManager ==
null) {
47 String method = call.method;
48 Map<String, Object>
args = call.arguments();
49 Log.
v(
TAG,
"Received '" + method +
"' message.");
50 final int loadingUnitId = (
int)
args.get(
"loadingUnitId");
51 final String componentName = (String)
args.get(
"componentName");
53 case "installDeferredComponent":
54 deferredComponentManager.installDeferredComponent(loadingUnitId, componentName);
55 if (!componentNameToResults.containsKey(componentName)) {
56 componentNameToResults.put(componentName,
new ArrayList<>());
58 componentNameToResults.get(componentName).add(
result);
60 case "getDeferredComponentInstallState":
62 deferredComponentManager.getDeferredComponentInstallState(
63 loadingUnitId, componentName));
65 case "uninstallDeferredComponent":
66 deferredComponentManager.uninstallDeferredComponent(loadingUnitId, componentName);
86 new MethodChannel(dartExecutor,
"flutter/deferredcomponent", StandardMethodCodec.INSTANCE);
88 deferredComponentManager =
FlutterInjector.instance().deferredComponentManager();
89 componentNameToResults =
new HashMap<>();
99 @Nullable DeferredComponentManager deferredComponentManager) {
100 this.deferredComponentManager = deferredComponentManager;
110 if (componentNameToResults.containsKey(componentName)) {
111 for (MethodChannel.Result
result : componentNameToResults.get(componentName)) {
114 componentNameToResults.get(componentName).clear();
127 if (componentNameToResults.containsKey(componentName)) {
128 for (MethodChannel.Result
result : componentNameToResults.get(componentName)) {
129 result.error(
"DeferredComponent Install failure", errorMessage,
null);
131 componentNameToResults.get(componentName).clear();
Type::kYUV Type::kRGBA() int(0.7 *637)
static void v(@NonNull String tag, @NonNull String message)
DeferredComponentChannel(@NonNull DartExecutor dartExecutor)
void completeInstallSuccess(String componentName)
void completeInstallError(String componentName, String errorMessage)
final MethodChannel.MethodCallHandler parsingMethodHandler
void setDeferredComponentManager( @Nullable DeferredComponentManager deferredComponentManager)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args