1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-13 10:27:09 +00:00

Adds data transfer to Add2App samples, using caching on Android (#146)

This commit is contained in:
Andrew Brogdon
2019-10-11 15:17:16 -07:00
committed by GitHub
parent f4a8247634
commit 947042d8df
10 changed files with 197 additions and 27 deletions

View File

@@ -18,21 +18,32 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cnf-d3-wlx">
<rect key="frame" x="105" y="432" width="204" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cnf-d3-wlx">
<rect key="frame" x="105" y="433" width="204" height="30"/>
<state key="normal" title="Launch Flutter ViewController"/>
<connections>
<action selector="buttonWasTapped:" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="yLP-26-wPf"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Current counter: 0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KJB-T1-vx3">
<rect key="frame" x="136.5" y="380" width="141" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Cnf-d3-wlx" firstAttribute="top" secondItem="KJB-T1-vx3" secondAttribute="bottom" constant="32" id="HZo-C0-7aM"/>
<constraint firstItem="Cnf-d3-wlx" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="IZY-8s-o5L"/>
<constraint firstItem="Cnf-d3-wlx" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="ofh-fr-CHR"/>
<constraint firstItem="KJB-T1-vx3" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="vxr-sw-WVe"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="counterLabel" destination="KJB-T1-vx3" id="Uph-NZ-re8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>

View File

@@ -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)
}
}
}