赞
踩
第一种简单接入Flutter module
1 先创建一个flutter moudle,在swift 项目的内的目录下
flutter create --template module flutter_test_module
2 然后在已经有的swift 项目中的podfile 文件中添加如下代码
//在顶部添加(flutter_test_module 就是moudle 的名字)
flutter_application_path = './flutter_test_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
//在target ‘xx' do下添加
install_all_flutter_pods(flutter_application_path)
3 然后执行 pod install
4 在swift 代码中添加跳转到flutter 中的方法,然后运行,
import UIKit import Flutter class ViewController: UIViewController { lazy var flutterEngine:FlutterEngine = FlutterEngine(name: "my flutter engine") override func viewDidLoad() { super.viewDidLoad() flutterEngine.run() // Do any additional setup after loading the view. } @IBAction func clikc(_ sender: Any) { let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil) self.present(flutterViewController, animated: true, completion: nil) } }
5 在flutter_test_module 目录下命令行执行 flutter attach
,然后就可以修改flutter中的代码,实时更新 ,使用 r
命令刷新界面,便可看到最新的修改,而不用启动项目
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。