flutter iOS 混編步驟

1.創(chuàng)建公共文件

image.png

2.創(chuàng)建iOS項目

image.png

3.創(chuàng)建flutter模塊

image.png
cd  xx/Hybrid Proj/
flutter create -t module flutter_module

iOS引入pod管理

cd xx/iOS HiHouse/
pod init

在profile文件中添加依賴,兩行需要放在Podfile頭部執(zhí)行:

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:

編寫代碼

原生代碼跳轉(zhuǎn)到flutter界面:

        //該參數(shù)用于告訴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<MyHomePage> {
  .....
}

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容