Skip to content

Instantly share code, notes, and snippets.

@li9ht
Last active December 1, 2021 02:22
Show Gist options
  • Save li9ht/ef737b4ba7141da8ada9319c3c226cb7 to your computer and use it in GitHub Desktop.
Save li9ht/ef737b4ba7141da8ada9319c3c226cb7 to your computer and use it in GitHub Desktop.
import UIKit
import Flutter
import FlutterPluginRegistrant
class ShowFlutterViewControler: UIViewController{
let userToken = "dummy123"
func showFlutter(){
let flutterEnggine = (UIApplication.shared.delegate as! AppDelegate).flutter_engine
let flutterController = FlutterViewController(engine:flutterEnggine,nibName:nil,bundle:nil)
let newsChannel = FlutterMethodChannel(name:"com.example.myflutterapp/data", binaryMessenger: flutterController.binaryMessenger)
newsChannel.setMethodCallHandler({
(call:FlutterMethodCall,result:@escaping FlutterResult) -> Void in
guard call.method == "getUserToken" else {
result("error")
return
}
if userToken.isEmpty {
result(FlutterError(code: "UNAVAILABLE",message: "Data not available",details: nil))
}else{
result(newsToken)
}
})
//start
//if your have scrollview in your flutter app
if #available(iOS 13.0, *) {
flutterController.isModalInPresentation = false
} else {
// Fallback on earlier versions
}
flutterController.modalPresentationStyle = .fullScreen
//end
self.present(flutterController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment