mirror of
https://github.com/flutter/samples.git
synced 2026-05-09 08:27:19 +00:00
Adds data transfer to Add2App samples, using caching on Android (#146)
This commit is contained in:
@@ -6,10 +6,43 @@ import UIKit
|
||||
import Flutter
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var counterLabel: UILabel!
|
||||
|
||||
var methodChannel : FlutterMethodChannel?
|
||||
var count = 0
|
||||
|
||||
override func viewDidLoad() {
|
||||
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
|
||||
methodChannel = FlutterMethodChannel(name: "dev.flutter.example/counter",
|
||||
binaryMessenger: flutterEngine.binaryMessenger)
|
||||
methodChannel?.setMethodCallHandler({ [weak self]
|
||||
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||||
if let strongSelf = self {
|
||||
switch(call.method) {
|
||||
case "incrementCounter":
|
||||
strongSelf.count += 1
|
||||
strongSelf.counterLabel.text = "Current counter: \(strongSelf.count)"
|
||||
strongSelf.reportCounter()
|
||||
case "requestCounter":
|
||||
strongSelf.reportCounter()
|
||||
default:
|
||||
// Unrecognized method name
|
||||
print("Unrecognized method name: \(call.method)")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func reportCounter() {
|
||||
methodChannel?.invokeMethod("reportCounter", arguments: count)
|
||||
}
|
||||
|
||||
@IBAction func buttonWasTapped(_ sender: Any) {
|
||||
let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine
|
||||
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)!
|
||||
self.present(flutterViewController, animated: false, completion: nil)
|
||||
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
|
||||
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
|
||||
self.present(flutterViewController, animated: false, completion: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user