最近应公司需求,需要模块化开发,在老项目中更换登录方式,登陆模块由flutter编写引入到项目中,记录学习flutter的过程以及集成过程中遇到的问题
首先flutter的文档:Flutter 中文文档 - Flutter 中文资源 | 将 Flutter module 集成到 iOS 项目
1、创建 Flutter module
cd some/path/
cd项目的同级目录
创建module:
flutter create --template module my_flutter
报错:bash: flutter: command not found
解决方法:
(如果确认之前已安装flutter,此步骤可省略,否则会报一些重复安装/链接的警告)
git clone -b beta https://github.com/flutter/flutter.git
export PUB_HOSTED_URL=https://pub.flutter-io.cn //(国内用户需设置)
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //(国内用户需设置)
export PATH=`pwd`/flutter/bin:$PATH
最后
source ~/.bashrc
输入完成后你的文件夹下就下载成功flutter,会有一个名为flutter的文件夹
2.终端输入:flutter build ios / flutter run
报错:[!] Invalid `Podfile` file: cannot load such file -- ./my_flutter/.ios/Flutter/podhelper.rb.
解决办法:cd flutter文件夹:$:flutter clean
$:flutter pub upgrade
cd到项目文件夹:pod install
会在文件夹下创建一个名为 my_flutter的文件夹
3、使用 CocoaPods 依赖管理和已安装的 Flutter SDK
在 `Podfile` 中添加下面代码:
flutter_application_path = '../my_flutter'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'MyApp' do
install_all_flutter_pods(flutter_application_path)
end
cd 到项目运行:运行 pod install
这样
Flutter module就集成到项目里了