1.创建Flutter模块
命令行cd到项目目录,执行命令行
flutter create --template module flutter_module
目录结构如下:
some/项目目录/
├── flutter_module/
│ └── .ios/
│ └── Flutter/
│ └── podhelper.rb
└── NativeDemo/
└── Podfile
2.设置Profile
以下行添加到Profile
platform :ios, '9.0'
use_frameworks!
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'NativeDemo' do
install_all_flutter_pods(flutter_application_path)
end
pod install

- 跳转flutter页面
import UIKit
import Flutter
import FlutterPluginRegistrant
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var flutterEngine = FlutterEngine(name: "my flutter engine")
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
flutterEngine.run()
GeneratedPluginRegistrant.register(with: self.flutterEngine)
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
window?.rootViewController = UIViewController()
window?.makeKeyAndVisible()
return true
}
}
import Flutter
class ViewController: UIViewController {
@objc func buttonAction(sender:UIButton) {
let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
present(flutterViewController, animated: true, completion: nil)
}
}
3.调试Flutter模块

Android Studio打开flutter main.dart改动之后保存就可以在模拟器上即时看到
网友评论