Flutter开发之——iOS原生项目导入Flutter,字节跳动架构师讲解Android开发

56 阅读3分钟

3.1 说明

创建IOS2Flutter文件夹,稍后将iOS和flutter项目都放在此文件夹下

3.2 创建IOS项目

  • 依次点击:File——>Project——>App

  • 设置对应的项目名称,机构id和编程语言

  • 选择文件的创建位置

四 创建Flutter module


  • 进入到IOS2Flutter文件夹(iOS项目文件夹),并在终端中打开

  • 执行如下指令创建Flutter module

flutter create --template module my_flutter

  • 执行后原生iOS和Flutter项目的目录结构

说明:

1-.ios 是隐藏目录,可以单独运行Flutter module,测试此模块的功能

2-iOS代码添加到现有应用程序的项目或插件中,而不是添加到模块的.ios /目录中

五 将Flutter嵌入到iOS应用程序中


5.1 嵌入方式说明

将Flutter嵌入到IOS应用程序中,使用:使用CocoaPods和已安装的Flutter SDK

5.2 创建IOS端Podfile文件

  • 终端进入到iOS项目路径下

cd MyApp/

  • 执行如下指令,生成Podfile文件

pod init

  • 默认创建的Podfile文件内容如下

Uncomment the next line to define a global platform for your project

platform :ios, '9.0'

target 'MyApp' do

Comment the next line if you don't want to use dynamic frameworks

use_frameworks!

Pods for MyApp

target 'MyAppTests' do

inherit! :search_paths

Pods for testing

end

target 'MyAppUITests' do

Pods for testing

end

end

  • 修改Podfile文件的内容(导入flutter模块)

Uncomment the next line to define a global platform for your project

platform :ios, '9.0'

flutter_application_path = '../my_flutter'

load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'MyApp' do

Comment the next line if you don't want to use dynamic frameworks

use_frameworks!

install_all_flutter_pods(flutter_application_path)

Pods for MyApp

target 'MyAppTests' do

inherit! :search_paths

install_all_flutter_pods(flutter_application_path)

Pods for testing

end

target 'MyAppUITests' do

install_all_flutter_pods(flutter_application_path)

Pods for testing

end

总结

作为一名从事Android的开发者,很多人最近都在和我吐槽Android是不是快要凉了?而在我看来这正是市场成熟的表现,所有的市场都是温水煮青蛙,永远会淘汰掉不愿意学习改变,安于现状的那批人,希望所有的人能在大浪淘沙中留下来,因为对于市场的逐渐成熟,平凡并不是我们唯一的答案! 在最后我整理了一份资料,而且我们为了感谢很多支持的学者,资料是无偿分享的,需要的同学可以来学习学习 领取方式:GitHub地址 资料.png 资料图.jpg