Last active
December 1, 2021 02:22
-
-
Save li9ht/ef737b4ba7141da8ada9319c3c226cb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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