Flutter - 将 Flutter 集成到现有项目(iOS - Framework篇)

本篇文章大幅参考了 caijinglong 大佬的总结文章: 把flutter作为framework添加到已存在的iOS中[1]

用 Flutter 来开发,从来都不可能是新开的一个纯 Flutter 项目,很大一部分都是 老项目接入 Flutter 来混编。

在 Flutter 官网 - Adding to an iOS app[2] 这里,官方也给出了一些将 Flutter 集成进入现有 iOS 项目的方法。但是,这些都多多少少的不符合我们的需求。

1. 从 Flutter Module 说起

想要把 Flutter 集成进现有 iOS 项目,我们就必须使用 Flutter Module

那就先用命令创建一个 Flutter Module:flutter create --template module flutter_test_module

6329e297edd093e6f84af2e9953f42e1.jpeg

Flutter APP 和 Flutter Module 的不同之处在于 pubspec.yaml 最后一段:

# This section identifies your Flutter project as a module meant for
# embedding in a native host app.  These identifiers should _not_ ordinarily
# be changed after generation - they are used to ensure that the tooling can
# maintain consistency when adding or modifying assets and plugins.
# They also do not have any bearing on your native host application's
# identifiers, which may be completely independent or the same as these.
module:
androidX: true
androidPackage: com.example.flutter_test_module
iosBundleIdentifier: com.example.flutterTestModule

这一段代码,把该 Flutter 项目标注为一个 module,用于嵌入到原生 app 里。

这里面设置了是否使用 androidx,Android 和 iOS 的 APP id。

2. iOS原生项目所需的文件

先说一下,iOS 原生项目引入 Flutter Module 需要如下 Framework:

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值