现有的iOS项目内嵌Flutter

2021-09-24  本文已影响0人  麦志超

1、创建Flutter module

终端执行以下命令,需要在iOS项目同一级目录下
flutter create -t module my_flutter

2、Podfile文件

platform :ios, '10.0'

flutter_application_path = '../my_flutter'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'XXXXX' do
  
  use_frameworks!
  
  install_all_flutter_pods(flutter_application_path)

end

3、执行 pod install

4、AppDelegate文件

import Flutter
import FlutterPluginRegistrant

class AppDelegate: FlutterAppDelegate
{
    //var window: UIWindow?
    
    lazy var flutterEngine = FlutterEngine(name: "my flutter engine")
    
    override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
    {
        flutterEngine.run()

        GeneratedPluginRegistrant.register(with: self.flutterEngine)
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

5、iOS跳转到Flutter页面

let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
let vc = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
navigationController?.pushViewController(vc, animated: true)
上一篇下一篇

猜你喜欢

热点阅读