For more information about how to configure and initialize an mPaaS environment for a Flutter project, see Access a Flutter project.
Use MCDP
Register MCDP View in native Android
Inheritance
io.flutter.plugin.platform.PlatformViewto provide a reference to theandroid.view.View.package com.example.mpaas_demo import android.content.Context import android.view.View import com.mpaas.cdp.CdpAdvertisementView import io.flutter.plugin.platform.PlatformView /** * MCDP view */ internal class NativeMcdpView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView { private val cdpView: CdpAdvertisementView override fun getView(): View { return cdpView } override fun dispose() {} init { cdpView = CdpAdvertisementView(context) if (creationParams != null) { cdpView.updateSpaceCode(creationParams["cdpCode"].toString()) } } }Create a factory class that is used to create instances of the
NativeView.package com.example.mpaas_demo import android.content.Context import io.flutter.plugin.common.StandardMessageCodec import io.flutter.plugin.platform.PlatformView import io.flutter.plugin.platform.PlatformViewFactory class NativeMcdpViewFactory (activity: MainActivity) : PlatformViewFactory(StandardMessageCodec.INSTANCE) { private val mContext = activity override fun create(context: Context, viewId: Int, args: Any?): PlatformView { val creationParams = args as Map<String?, Any?>? return NativeMcdpView(mContext, viewId, creationParams) } }
Register a platform view in an application
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine
.platformViewsController
.registry
.registerViewFactory("<mcdp-platform-view-type>", NativeMcdpViewFactory(this))
}Use MCDP in Flutter
Create a MCDP
Widget.import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; class McdpView extends StatelessWidget { final String cdpCode; McdpView({Key? key, required this.cdpCode}) : super(key: key); String viewType = '<mcdp-platform-view-type>'; @override Widget build(BuildContext context) { const StandardMessageCodec _decoder = StandardMessageCodec(); if (defaultTargetPlatform == TargetPlatform.android) { return Expanded( child: AndroidView( viewType: viewType, creationParams: {"cdpCode": cdpCode}, creationParamsCodec: _decoder, ), ); } else { return Container(); } } }Use MCDP Widget.
McdpView( cdpCode: 'slideshow1'),