Last updated:
0 purchases
extended platform view
ExtendedPlatformView #
Adds the ExtendedPlatformView widget to simplify PlatformView initialization & communication.
ExtendedPlatformView has these functionalities.
Use the single ExtendedPlatformView widget to create PlatformView on Android and iOS
MethodChannel support
Switching HybridComposition and VirtualDisplay on Android
How to Use #
Create an ExtendedPlatformView widget [Flutter] #
Widget build(BuildContext context) {
return ExtendedPlatformView(
config: const ExtendedPlatformViewConfig(
viewType: 'sample_platform_view',
creationParams: "text",
),
);
}
copied to clipboard
Add PlatformView class & register viewType [Android] #
Add PlatformView class that extends the ExtendedPlatformView
class SamplePlatformView: ExtendedPlatformView() {
override fun initialize(params: CreationParams): View {
return TextView(context).apply {
text = params.args as String
}
}
}
copied to clipboard
Register the PlatformView on FlutterActivity
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine.extendedPlatformView.register("sample_platform_view") { SamplePlatformView() }
}
}
copied to clipboard
Add PlatformView class & register viewType [iOS] #
Add PlatformView class that extends the ExtendedPlatformView
import extended_platform_view
class SamplePlatformView: ExtendedPlatformView {
override func initialize(params: CreationParams) -> UIView {
let label = UILabel(frame: params.frame)
label.text = (params.args as! String)
return label
}
}
copied to clipboard
Register the PlatformView on AppDelegate
import extended_platform_view
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// You have to register ExtendedPlatformView before calling `GeneratedPluginRegistrant.register(with: self)`
ExtendedPlatformViewRegistrar.register(viewType: "sample_platform_view", builder: { SamplePlatformView() })
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
copied to clipboard
MethodChannel #
MethodChannel will be created if you pass the methodChannelDelegate argument.
On the platform side, ExtendedPlatformView has methodChannel property and
it will be assigned automatically before the initialize(params: CreationParams) method call.
Widget build(BuildContext context) {
return ExtendedPlatformView(
config: const ExtendedPlatformViewConfig(
viewType: 'sample_platform_view',
creationParams: "text",
),
methodChannelDelegate: MethodChannelDelegate(
onCreate: (methodChannel) {
// do something...
},
),
);
}
copied to clipboard
On Android
override fun initialize(params: CreationParams): View {
val textView = TextView(context).apply {
text = params.args as String
}
methodChannel.setMethodCallHandler { call, result ->
// do something...
}
return textView
}
copied to clipboard
On iOS
override func initialize(params: CreationParams) -> UIView {
let label = UILabel(frame: params.frame)
label.text = (params.args as! String)
methodChannel.setMethodCallHandler({ call, result in
// do something...
})
return label
}
copied to clipboard
AndroidCompositionMode #
Flutter has two PlatformView composition mode on Android.
By default, ExtendedPlatformView will use the HybridComposition.
If you need to use the VirtualDisplay mode, set the ExtendedPlatformViewConfig.androidCompositionMode to AndroidCompositionMode.virtualDisplay
ExtendedPlatformViewConfig(
viewType: 'sample_platform_view',
androidCompositionMode: AndroidCompositionMode.virtualDisplay,
)
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.