Flutter 工程化框架选择 — 混合开发的摸爬滚打_platformviewsservice
    		       		warning:
    		            这篇文章距离上次修改已过434天,其中的内容可能已经有所变动。
    		        
        		                
                在Flutter中实现混合开发通常有两种主要方式:
- 使用PlatformView: 这是Flutter提供的一种方式,允许你在Flutter Widget树中嵌入原生视图。你可以通过创建一个AndroidView或UiKitView来在你的Flutter应用中嵌入Android或iOS的原生控件。
- 使用webview: 如果你需要展示的是web内容,你可以使用Flutter提供的webview_flutter插件。
在选择这些混合开发方案时,你需要考虑的关键因素包括性能、兼容性、功能和开发效率。
对于platformviewsservice,这是Android上用于处理Flutter中PlatformView的后台服务。在Android项目中,你需要在AndroidManifest.xml中添加对应的服务定义,以确保Flutter可以正确地使用PlatformView。
<application>
    <!-- ... other elements ... -->
    <service
        android:name="io.flutter.plugins.platformviews.PlatformViewsService"
        android:process=":flutter_view"
        android:exported="false">
        <intent-filter>
            <action android:name="io.flutter.view.PlatformViewsService" />
        </intent-filter>
    </service>
</application>在iOS项目中,你需要确保项目中包含了FlutterPlugin,并且正确地处理了Platform Channel的通信。
import UIKit
import Flutter
 
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
  ) {
    FlutterPushNotificationPlugin.setDeviceToken(deviceToken)
  }
  
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}在选择混合开发框架时,你需要根据你的具体需求来决定。如果你需要嵌入复杂的原生控件或者需要与原生代码进行大量交互,PlatformView可能更适合。如果你主要是展示web内容,使用webview可能是更简单的选择。
评论已关闭