flutter iOS 混编步骤

1.创建公共文件

flutter iOS 混编步骤_第1张图片
image.png

2.创建iOS项目

flutter iOS 混编步骤_第2张图片
image.png

3.创建flutter模块

flutter iOS 混编步骤_第3张图片
image.png
cd  xx/Hybrid Proj/
flutter create -t module flutter_module

iOS引入pod管理

cd xx/iOS HiHouse/
pod init

在profile文件中添加依赖,两行需要放在Podfile头部执行:

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

在各个target里面添加:

    #flutter
    install_all_flutter_pods(flutter_application_path)

安装依赖:

pod install

注意:禁用Bitcode:

编写代码

原生代码跳转到flutter界面:

        //该参数用于告诉Dart代码显示哪个Flutter视图。
        vc.setInitialRoute("myApp")
        self.present(vc, animated: true) {
            //
        }
        return;

flutter模块里面:

import 'dart:ui';
import 'package:flutter/material.dart';

void main() => runApp(_widgetForRoute(window.defaultRouteName));

Widget _widgetForRoute(String route) {
  switch (route) {
    case 'myApp':
      return MyApp();
    default:
      return MaterialApp(
        home: Center(
          child: Text('没找到'),
        ),
      );
  }
}


class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
            ...
      ),
      home: MyHomePage(title: 'test'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  .....
}

你可能感兴趣的:(flutter iOS 混编步骤)