Generate projects using the new Android embedding (#41666)

* Generate projects using the new Android embedding

* Add comment about usesNewEmbedding:true

* Feedback

* Rework way to detect new embedding in new apps
This commit is contained in:
Emmanuel Garcia
2019-10-04 06:23:03 -07:00
committed by GitHub
parent 890b939401
commit 5961bcc505
20 changed files with 802 additions and 35 deletions

View File

@@ -1,5 +1,37 @@
package {{androidIdentifier}};
{{#useNewAndroidEmbedding}}
{{#androidX}}
import androidx.annotation.NonNull;
{{/androidX}}
{{^androidX}}
import android.support.annotation.NonNull;
{{/androidX}}
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
/** {{pluginClass}} */
public class {{pluginClass}} implements FlutterPlugin, MethodCallHandler {
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
final MethodChannel channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "{{projectName}}");
channel.setMethodCallHandler(new {{pluginClass}}());
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else {
result.notImplemented();
}
}
}
{{/useNewAndroidEmbedding}}
{{^useNewAndroidEmbedding}}
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
@@ -23,3 +55,4 @@ public class {{pluginClass}} implements MethodCallHandler {
}
}
}
{{/useNewAndroidEmbedding}}