当前位置: 首页 > news >正文

Flutter与iOS原生混合开发 iOS项目集成Flutter

1.创建flutter module
进入iOS工程根目录的上一级,创建flutter module工程

flutter create --template module fluttermodule

2.进入iOS工程根目录,编辑podfile文件

flutter_application_path = '../fluttermodule'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')target "iOSDemo" douse_frameworks!
install_all_flutter_pods(flutter_application_path)endpost_install do |installer|flutter_post_install(installer) if defined?(flutter_post_install)
end

执行pod install
3.iOS调用Flutter
在AppDelegate注册FlutterEngine

import UIKit
import Flutter
import FlutterPluginRegistrant@main
class AppDelegate: UIResponder, UIApplicationDelegate {lazy var flutterEngine = FlutterEngine(name: "my flutter engine")func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Override point for customization after application launch.GeneratedPluginRegistrant.register(with: self.flutterEngine);flutterEngine.run()return true}
}

使用 FlutterEngine调用utterViewController

import UIKit
import Flutterclass ViewController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// Make a button to call the showFlutter function when pressed.let button = UIButton(type:UIButton.ButtonType.custom)button.addTarget(self, action: #selector(showFlutter), for: .touchUpInside)button.setTitle("Show Flutter!", for: UIControl.State.normal)button.frame = CGRect(x: 80.0, y: 210.0, width: 160.0, height: 40.0)button.backgroundColor = UIColor.blueself.view.addSubview(button)}@objc func showFlutter() {let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEnginelet flutterViewController =FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)present(flutterViewController, animated: true, completion: nil)}
}

参考链接
https://www.jianshu.com/p/aac1f387f3c0
https://www.jianshu.com/p/c3e5e210a585

相关文章:

  • (杂交版)植物大战僵尸
  • 流批一体计算引擎-10-[Flink]中的常用算子和DataStream转换
  • OpenCV的核心数据结构
  • codereview时通常需要关注哪些
  • Mongodb---java篇
  • 简述React 和 Vue 的 diff 时间复杂度从 O(n^3) 优化 到 O(n) ,那么 O(n^3) 和 O(n) 是如何计算出来的 ?
  • 特征提取(Feature Extraction)特征评估(五)
  • 【Linux】The server quit without updating PID file的几种解决方案
  • ubuntu20.04设置文件开机自启动
  • 持续总结中!2024年面试必问 20 道分布式、微服务面试题(二)
  • ffmpeg视频编码原理和实战-(2)视频帧的创建和编码packet压缩
  • 6.4分享会
  • 2024全国高考作文题解读(Chat GPT 4.0版本)
  • 讯方618代表有话说 | 行业大咖详解鸿蒙,全程在线答疑
  • java static 如何理解
  • 【402天】跃迁之路——程序员高效学习方法论探索系列(实验阶段159-2018.03.14)...
  • 【vuex入门系列02】mutation接收单个参数和多个参数
  • input实现文字超出省略号功能
  • Java读取Properties文件的六种方法
  • js对象的深浅拷贝
  • JS函数式编程 数组部分风格 ES6版
  • maya建模与骨骼动画快速实现人工鱼
  • PhantomJS 安装
  • Python学习之路16-使用API
  • Unix命令
  • 番外篇1:在Windows环境下安装JDK
  • 计算机在识别图像时“看到”了什么?
  • 面试遇到的一些题
  • 让你的分享飞起来——极光推出社会化分享组件
  • 什么是Javascript函数节流?
  • 世界上最简单的无等待算法(getAndIncrement)
  • 微信小程序--------语音识别(前端自己也能玩)
  • 小而合理的前端理论:rscss和rsjs
  • 追踪解析 FutureTask 源码
  • 【干货分享】dos命令大全
  • Python 之网络式编程
  • 树莓派用上kodexplorer也能玩成私有网盘
  • ​configparser --- 配置文件解析器​
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #565. 查找之大编号
  • (12)Linux 常见的三种进程状态
  • (2024,Vision-LSTM,ViL,xLSTM,ViT,ViM,双向扫描)xLSTM 作为通用视觉骨干
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (C语言)球球大作战
  • (Java实习生)每日10道面试题打卡——JavaWeb篇
  • (笔记)M1使用hombrew安装qemu
  • (第27天)Oracle 数据泵转换分区表
  • (附源码)ssm跨平台教学系统 毕业设计 280843
  • (十八)SpringBoot之发送QQ邮件
  • (一)使用Mybatis实现在student数据库中插入一个学生信息
  • (原創) 如何將struct塞進vector? (C/C++) (STL)
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • .net core 源码_ASP.NET Core之Identity源码学习
  • .Net Framework 4.x 程序到底运行在哪个 CLR 版本之上
  • .net php 通信,flash与asp/php/asp.net通信的方法