Ios 集成 Flutter Frameworks
使用命令生成 frameworks flutter build ios-framework --xcframework --no-universal
生成 App.xcframework 和 Flutter.xcframework
-
拖拽 frameworks 到你的应用 target 编译设置的 General > Frameworks, Libraries, and Embedded Content 下,然后在 Embed 下拉列表中选择 “Embed & Sign”。
-
初始化flutterEngine
import UIKit
import Flutter
@main
class AppDelegate: FlutterAppDelegate {
lazy var flutterEngine = FlutterEngine(name: "hgg_im")
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// return true
// Runs the default Dart entrypoint with a default Flutter route.
flutterEngine.run();
// Used to connect plugins (only if you have plugins with iOS platform code).
return super.application(application, didFinishLaunchingWithOptions: launchOptions);
}
}
-
启动页面
let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil) //flutterViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen; present(flutterViewController, animated: true, completion: nil)