美文网首页Flutter 开发技巧
在现有的iOS工程中接入Flutter

在现有的iOS工程中接入Flutter

作者: mark666 | 来源:发表于2020-05-26 09:47 被阅读0次

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 直接调试,但是如果有个多个应用或者设备需要指定对应的设备

  • 参考文档

官方文档

相关文章

网友评论

    本文标题:在现有的iOS工程中接入Flutter

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