美文网首页
现有的iOS项目内嵌Flutter

现有的iOS项目内嵌Flutter

作者: 麦志超 | 来源:发表于2021-09-24 18: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)
    

    相关文章

      网友评论

          本文标题:现有的iOS项目内嵌Flutter

          本文链接:https://www.haomeiwen.com/subject/keizgltx.html