欢迎您光临深圳塔灯网络科技有限公司!
电话图标 余先生:13699882642

网站百科

为您解码网站建设的点点滴滴

Flutter与iOS混编(pod)

发表日期:2018-11 文章编辑:小灯 浏览次数:4147

一、配置过程

  • 1. 新建一个xcode工程:FlutterNativeFrame
    跟flutter在同级别路径

    image.png

  • 2. binding flutter

// flutter_application_path:flutter工程的绝对路径 flutter_application_path = '**/**/my_flutter' eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding) 
image.png
  • 3.执行pod install
    执行完之后,打开xcode工程,出现如图所示的两个文件夹,success

    image.png

  • 4. 添加脚本文件
    "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed

    image.png

image.png

ok,run,如果运行报错,把Enable Bitcode 设为NO,Flutter混合开发还不支持bit code,所以在iOS工程检查项目并关闭bit code

image.png

现在应该可以运行起来了,如果还是不行,重复以上步骤

混编开始:
修改AppDelegate.h、AppDelegate.m

// .h #import <UIKit/UIKit.h> #import <Flutter/Flutter.h>@interface AppDelegate : FlutterAppDelegate @end// .m #import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h> // Only if you have Flutter Plugins#include "AppDelegate.h"@implementation AppDelegate// This override can be omitted if you do not have any Flutter Plugins. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; }@end 

ViewController跳转

#import <Flutter/Flutter.h> #import "ViewController.h"@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:selfaction:@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]; }- (void)handleButtonAction { FlutterViewController* flutterViewController = [[FlutterViewController alloc] init]; [self presentViewController:flutterViewController animated:false completion:nil]; } @end 

二、热更新 Hot Reload

cd到flutter工程路径,执行flutter attach
attach成功之后,运行xcode,更新直接press 'r'

image.png

在VStudio中修改dart文件,press 'r'直接可以看到修改之后的显示

官网链接:Hot reload https://flutter.io/docs/development/tools/hot-reload


本页内容由塔灯网络科技有限公司通过网络收集编辑所得,所有资料仅供用户学习参考,本站不拥有所有权,如您认为本网页中由涉嫌抄袭的内容,请及时与我们联系,并提供相关证据,工作人员会在5工作日内联系您,一经查实,本站立刻删除侵权内容。本文链接:http://dengtar.com/17756.html
相关APP开发
    SQL执行错误,请检查