1.创建Flutter模块
在现有的iOS工程路径下,创建Flutter
模块:
cd ~/Work/Projects // 项目文件夹
flutter create -t module flutter_module
2 创建依赖
- 在Podfile 文件中添加
Flutter app
,在Podfile
文件中添加:
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'xx' do
use_frameworks!
# 安装Flutter模块
install_all_flutter_pods(flutter_application_path)
end
执行 pod install
3.运行
- 在iOS 项目中,通过
FlutterViewController
跳转至Flutter
页面
1.创建初始化引擎
self.flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
[self.flutterEngine run];
2.在合适的地方弹出视图
FlutterEngine *flutterEngine =
((AppDelegate *)UIApplication.sharedApplication.delegate).flutterEngine;
FlutterViewController *flutterViewController =
[[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];
[self presentViewController:flutterViewController animated:YES completion:nil];
Flutter模块调试
这里说一个热重载的方法 (Hot Reload)调试
flutter attach --app-id com.coderwhy.ios-my-test -d 3D7A877C-B0DD-4871-8D6E-0C5263B986CD
-
--app-id
后面跟的是 应用的bundId -
-d
是应用的设备id
可以直接执行 flutter attach
直接调试,但是如果有个多个应用或者设备需要指定对应的设备
- 参考文档
网友评论