發表日期:2018-09 文章編輯:小燈 瀏覽次數:3625
參考:https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
本文代碼:https://github.com/yonglinwang002/TestFlutter
假設已有工程 TestFlutter
$ cd TestFlutter/
$ flutter create -t module flutter_library
執行后會生成
flutter_library 目錄
結構如下
在主工程中增加一個 Group 如名為Flutter
生成后結構
TestFlutter/
? ? Flutter/
? ? ? Flutter.xcconfig
? ? TestFlutter/
? ? ? AppDelegate.h
? ? ? AppDelegate.m
? ? ? :
? ? ? Debug.xcconfig
? ? ? Release.xcconfig
編輯Flutter.xcconfig 文件
#include "../flutter_library/.ios/Flutter/Generated.xcconfig"
ENABLE_BITCODE=NO
Debug.xcconfig文件
#include "../Flutter/Flutter.xcconfig"
Release.xcconfig文件
#include "../Flutter/Flutter.xcconfig"
FLUTTER_BUILD_MODE=release
使用xcconfig相應配置
在Run Script中增加
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
Cmd+B,Build工程,編譯后,Flutter目錄中生成如下
把其中的flutter_assets 目錄以及Flutter.framework加入到工程的Flutter Group中
注意添加flutter_assets目錄時,選擇 Create forlder references !!!! (我就是這里沒注意,后面始終出錯)
這里就沒有什么好說的了,
#import "Flutter/Flutter.h"
- (void)viewDidLoad {
??? [super viewDidLoad];
??? [self.view setBackgroundColor:[UIColor orangeColor]];
???
??? UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
??? [button addTarget:self
?????????????? action:@selector(handleButtonAction)
???? forControlEvents:UIControlEventTouchUpInside];
??? [button setTitle:@"Press me" forState:UIControlStateNormal];
??? [button setBackgroundColor:[UIColor blueColor]];
??? button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
??? [self.view addSubview:button];
???
??? // Do any additional setup after loading the view, typically from a nib.
}
- (void)handleButtonAction {
??? FlutterViewController* flutterViewController = [[FlutterViewController alloc] init];
??? flutterViewController.view.frame = [UIScreen mainScreen].bounds;
//??? [flutterViewController setInitialRoute:@"route1"];//如果設置了router,可以到不同的頁面
??? [self presentViewController:flutterViewController animated:NO completion:nil];
}
Cmd+R吧,就出來了
這里說一個熱重載的方法 (Hot Reload) 在終端上
$ cd flutter_library
$ flutter attach
Waiting for a connection from Flutter on iPhone X...
然后,在XCode中 Cmd+R 執行,待進入到FlutterView頁面時,
終端變成如下
這時如果修改了dart文件 ,再按r就可以重新載入
q 退出
日期:2018-10 瀏覽次數:7525
日期:2018-12 瀏覽次數:4598
日期:2018-07 瀏覽次數:5115
日期:2018-12 瀏覽次數:4402
日期:2018-09 瀏覽次數:5756
日期:2018-12 瀏覽次數:10181
日期:2018-11 瀏覽次數:5091
日期:2018-07 瀏覽次數:4845
日期:2018-05 瀏覽次數:5098
日期:2018-12 瀏覽次數:4562
日期:2018-10 瀏覽次數:5377
日期:2018-12 瀏覽次數:6438
日期:2018-11 瀏覽次數:4705
日期:2018-08 瀏覽次數:4850
日期:2018-11 瀏覽次數:12938
日期:2018-09 瀏覽次數:5858
日期:2018-12 瀏覽次數:5084
日期:2018-10 瀏覽次數:4423
日期:2018-11 瀏覽次數:4769
日期:2018-12 瀏覽次數:6299
日期:2018-06 瀏覽次數:4249
日期:2018-08 瀏覽次數:5697
日期:2018-10 瀏覽次數:4681
日期:2018-12 瀏覽次數:4792
日期:2018-07 瀏覽次數:4614
日期:2018-12 瀏覽次數:4783
日期:2018-06 瀏覽次數:4623
日期:2018-11 瀏覽次數:4603
日期:2018-12 瀏覽次數:4526
日期:2018-12 瀏覽次數:5507
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.