<address id="r9vd9"><address id="r9vd9"><listing id="r9vd9"></listing></address></address>

      歡迎您光臨深圳塔燈網絡科技有限公司!
      電話圖標 余先生:13699882642

      網站百科

      為您解碼網站建設的點點滴滴

      iOS 項目集成Flutter

      發表日期:2018-11 文章編輯:小燈 瀏覽次數:1901

      最近移動端火爆無非是Flutter--舍我其誰,而官網的引導之中鮮有說怎么在已有項目中去集成Flutter,今天我們就再蹭個熱門來進行一個iOS集成

      1 創建iOS項目(做測試使用)
      2 cocoapods走起

      project 'XX.xcodeproj' #source 'https://github.com/CocoaPods/Specs.git' #platform :ios, '9.0' #inhibit_all_warnings! # Uncomment the next line to define a global platform for your project # platform :ios, '9.0'target 'XX' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks!# Pods for XXtarget 'XXTests' do inherit! :search_paths # Pods for testing endtarget 'XXUITests' do inherit! :search_paths # Pods for testing endend flutter_application_path = './flutter_module' eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding) 

      關鍵部鋒分就是末尾添加的

      flutter_application_path = './flutter_module' eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding) 

      3 進入項目根目錄添加flutter_module

      flutter create -t module flutter_module 

      4 Xcode 設置
      Build Phases 添加 Run Scripts

      "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build 

      4 pod install

      5 code設置
      5.1 Appdelegate

      #import <Flutter/Flutter.h> @interface AppDelegate : FlutterAppDelegate//@property (strong, nonatomic) UIWindow *window; @end 
      #import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h> // Only if you have Flutter Plugins- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } 

      5.2 Controller切換

       - (IBAction)pushFlutterVC:(id)sender { FlutterViewController *flutterViewController = [[FlutterViewController alloc] init]; flutterViewController.view.backgroundColor = [UIColor cyanColor]; [flutterViewController setInitialRoute:@"route1"];[self presentViewController:flutterViewControlleranimated:YES completion:^{UIViewController * vc = [[NextViewController alloc] init]; // vc.view.backgroundColor = [UIColor whiteColor];AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;UIViewController * rootVC = appDelegate.window.rootViewController;UIViewController * topVC = nil;if ([rootVC isKindOfClass:[UINavigationController class]]) { topVC =((UINavigationController *)rootVC).topViewController.presentedViewController;} else {topVC =rootVC.presentedViewController;}[topVC presentViewController:vc animated:YES completion:nil];}]; } 

      5.2中我們要考慮到首頁是Nav UIViewCOntrooler 或者是FlutterViewController
      到此我們的就可以直接Xcode run運行項目啦

      6 假如想實現hot reload

      進入項目中的flutter_module,運行 flutter attach 
      熱更新
      本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶學習參考,本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.webpost.com.cn/17534.html
      相關APP開發
        SQL執行錯誤,請檢查国产成人精品综合在线观看