原文 http://summerxx.com/2023/01/28/ios-use-flutter/
前言: 上篇我講了下 flutter 環(huán)境在 MacOs 下搭建, 今天寫(xiě)下如何在一個(gè)成熟的 iOS 項(xiàng)目?jī)?nèi)引用 flutter, Demo 會(huì)放到文章最后哈
上篇 : MacOS 下配置flutter 環(huán)境
大致如下:
在項(xiàng)目?jī)?nèi)創(chuàng)建一個(gè) flutter 模塊
新建一個(gè) Podfile, 然后進(jìn)行編寫(xiě), 之后安裝
修改 Xcode 配置, 再次安裝
書(shū)寫(xiě), 測(cè)試 flutter頁(yè)面
創(chuàng)建一個(gè) flutter 模塊
flutter create --template module flutter_module
創(chuàng)建一個(gè) Podfile
platform :ios, '11.0'
flutter_application_path = 'flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'ios_flutter_demo' do
use_frameworks!
install_all_flutter_pods(flutter_application_path)
pod 'AFNetworking'
end
# 新增的配置
post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end
安裝
pod install
錯(cuò)誤

截屏2023-01-28 17.21.38
修改Xcode 配置

截屏2023-01-28 17.05.32
之后重新安裝 pod, 就會(huì)在項(xiàng)目里面成功引用了 flutter 相關(guān)的包, 如下圖所示

截屏2023-01-28 17.38.43
測(cè)試代碼
#import "ViewController.h"
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import <Flutter/Flutter.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupViews];
}
- (void)setupViews
{
UIButton *test = [UIButton buttonWithType:UIButtonTypeCustom];
test.backgroundColor = UIColor.blueColor;
[test setTitle:@"Test Flutter" forState:UIControlStateNormal];
[self.view addSubview:test];
[test mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(0);
make.top.mas_equalTo(100);
make.height.mas_equalTo(50);
}];
[[test rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
NSLog(@"按鈕被點(diǎn)擊了");
FlutterViewController *vc = [[FlutterViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
}];
}
@end
效果圖

https://p.ipic.vip/myq7c3.png
問(wèn)題 Specs satisfying the Flutter (fromflutter_module/.ios/Flutter) dependency were found, but they required a higher minimum deployment target.
解決 https://blog.csdn.net/u011519923/article/details/116785638
文章參照 :
https://blog.csdn.net/jdd92/article/details/121938342
Demo: