美文网首页Flutter
Flutter模块集成到Swift项目

Flutter模块集成到Swift项目

作者: 北纬357 | 来源:发表于2020-07-29 17:34 被阅读0次

《参考地址》

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


截屏2020-07-29 下午2.57.03.png
  • 跳转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模块

截屏2020-07-29 下午4.04.50.png

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

相关文章

网友评论

    本文标题:Flutter模块集成到Swift项目

    本文链接:https://www.haomeiwen.com/subject/iibhrktx.html