1.創(chuàng)建公共文件
image.png
2.創(chuàng)建iOS項(xiàng)目
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)
在各個(gè)target里面添加:
#flutter
install_all_flutter_pods(flutter_application_path)
安裝依賴:
pod install
注意:禁用Bitcode:
編寫代碼
原生代碼跳轉(zhuǎn)到flutter界面:
//該參數(shù)用于告訴Dart代碼顯示哪個(gè)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('沒(méi)找到'),
),
);
}
}
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> {
.....
}