美文网首页
2022-11-02

2022-11-02

作者: 刚刚下课 | 来源:发表于2022-11-02 17:18 被阅读0次

                                        ios 原生项目嵌入 Flutter模块项目

本文章和网上不同,需要一定ios  Flutter开发经验    网上说的创建什么Flutter_module 其实就是已有的flutter项目

准备资源:可运行的flutter项目,ios原生项目 各一份

第一步: 删除Flutter项目中的 ios、android和编译过的build文件夹(就是运行时产生的,再嵌入时是不需要的,只需要隐藏文件:.ios/就可以)如果找不到.ios文件  执行快捷键command+shift+.显示隐藏文件夹,如果还找不到在项目的在pubspec.yaml 中加入以下代码,保存后在看:

module:

androidX:true

androidPackage:com.example.flutter_base_component

iosBundleIdentifier:com.example.flutterBaseComponent

第二步:然后在flutter项目中执行:flutter clean     和       flutterpubupgrade

第三步:接下来转到ios项目中在Profile文件中添加如下代码,然后执行pod install:有版本报错可以修改第一行 11改成12   我是从9改上来的,10也不行 11运行正常

platform :ios,'11.0'

flutter_application_path ='../xiyou_flutter_sdk'

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

target 'XiYouGames' do

 install_all_flutter_pods(flutter_application_path)

 post_installdo|installer|

   flutter_post_install(installer)ifdefined?(flutter_post_install)

 end

  use_frameworks!

  inhibit_all_warnings!

 end

第四步:运行完成后就可以在原生ios项目中写跳转方法了  我的跳转方法如下

引入头文件#import      <Flutter/Flutter.h>(如果找不到、再去执行一遍第二步和pod install)

    FlutterViewController *flutterViewController =[FlutterViewController new];

    //设置路由参数

    [flutterViewControllersetInitialRoute:@"teamDetail"];

    [self presentViewController:flutterViewController animated:YES completion:nil];

相关文章

网友评论

      本文标题:2022-11-02

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