I want to run a custom Swift UI page in my flutter application. I am trying to call ios platform specific code using method channel. My target is when i call a method using method channel i will present the Swift UI view in front of user.
My AppDelegate.swift file is below:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let batteryChannel = FlutterMethodChannel(name: "yourpackageName/channelName",
binaryMessenger: controller.binaryMessenger)
batteryChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "showPage"{
//run a swift ui view here
}
})
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
And my custom Swift UI file is below:
import SwiftUI
@available(iOS 13.0, *)
struct CustomPage: View {
var body: some View {
Text("Hello, World!")
}
}
@available(iOS 13.0, *)
struct CustomPage_Previews: PreviewProvider {
static var previews: some View {
CustomPage()
}
}
Is there any way i can achieve this?