IOS开发:在原生项目中添加flutter模块

1、创建flutter模块
image.png

2、创建Xcode工程,并使用cocopods管理工程依赖;

3、将flutter模块、Xcode工程放在同级目录下;配置Podfile文件、将flutter模块添加到Xcode工程;
image.png
//配置Podfile文件
#配置flutter模块路径
flutter_application_path = '../mudule_demo'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'ios_flutter' do
  use_frameworks!
#指定需要安装的flutter模块
  install_all_flutter_pods(flutter_application_path)
end

4、原始层代码

import UIKit
import Flutter

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.yellow
    }


    override func touchesBegan(_ touches: Set, with event: UIEvent?) {
        let flutterViewController = FlutterViewController(project: nil, nibName: nil, bundle: nil)
        present(flutterViewController, animated: true, completion: nil)
    }
}

5、OK,大功告成


成功.gif

你可能感兴趣的:(IOS开发:在原生项目中添加flutter模块)