Skip to content

Instantly share code, notes, and snippets.

@ashishrawat2911
Last active January 8, 2019 13:41
Show Gist options
  • Save ashishrawat2911/5a366ef321fd1fcbee04593d44faea00 to your computer and use it in GitHub Desktop.
Save ashishrawat2911/5a366ef321fd1fcbee04593d44faea00 to your computer and use it in GitHub Desktop.
import Flutter
import UIKit
public class SwiftFlutterAlertDemoPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_alert_demo", binaryMessenger: registrar.messenger())
let instance = SwiftFlutterAlertDemoPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
if (call.method == "getPlatformVersion") {
result("iOS " + UIDevice.current.systemVersion)
}
else if (call.method == "showAlertDialog") {
DispatchQueue.main.async {
let alert = UIAlertController(title: "Alert", message: "Hi, My name is flutter", preferredStyle: .alert);
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment