| // Copyright 2013 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // Autogenerated from Pigeon (v9.1.0), do not edit directly. |
| // See also: https://pub.dev/packages/pigeon |
| |
| import Foundation |
| #if os(iOS) |
| import Flutter |
| #elseif os(macOS) |
| import FlutterMacOS |
| #else |
| #error("Unsupported platform.") |
| #endif |
| |
| |
| |
| private func wrapResult(_ result: Any?) -> [Any?] { |
| return [result] |
| } |
| |
| private func wrapError(_ error: Any) -> [Any?] { |
| if let flutterError = error as? FlutterError { |
| return [ |
| flutterError.code, |
| flutterError.message, |
| flutterError.details |
| ] |
| } |
| return [ |
| "\(error)", |
| "\(type(of: error))", |
| "Stacktrace: \(Thread.callStackSymbols)" |
| ] |
| } |
| /// Generated protocol from Pigeon that represents a handler of messages from Flutter. |
| protocol UserDefaultsApi { |
| func remove(key: String) throws |
| func setBool(key: String, value: Bool) throws |
| func setDouble(key: String, value: Double) throws |
| func setValue(key: String, value: Any) throws |
| func getAllWithPrefix(prefix: String) throws -> [String?: Any?] |
| func clearWithPrefix(prefix: String) throws |
| } |
| |
| /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. |
| class UserDefaultsApiSetup { |
| /// The codec used by UserDefaultsApi. |
| /// Sets up an instance of `UserDefaultsApi` to handle messages through the `binaryMessenger`. |
| static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UserDefaultsApi?) { |
| let removeChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.remove", binaryMessenger: binaryMessenger) |
| if let api = api { |
| removeChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let keyArg = args[0] as! String |
| do { |
| try api.remove(key: keyArg) |
| reply(wrapResult(nil)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| removeChannel.setMessageHandler(nil) |
| } |
| let setBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.setBool", binaryMessenger: binaryMessenger) |
| if let api = api { |
| setBoolChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let keyArg = args[0] as! String |
| let valueArg = args[1] as! Bool |
| do { |
| try api.setBool(key: keyArg, value: valueArg) |
| reply(wrapResult(nil)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| setBoolChannel.setMessageHandler(nil) |
| } |
| let setDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.setDouble", binaryMessenger: binaryMessenger) |
| if let api = api { |
| setDoubleChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let keyArg = args[0] as! String |
| let valueArg = args[1] as! Double |
| do { |
| try api.setDouble(key: keyArg, value: valueArg) |
| reply(wrapResult(nil)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| setDoubleChannel.setMessageHandler(nil) |
| } |
| let setValueChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.setValue", binaryMessenger: binaryMessenger) |
| if let api = api { |
| setValueChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let keyArg = args[0] as! String |
| let valueArg = args[1] |
| do { |
| try api.setValue(key: keyArg, value: valueArg) |
| reply(wrapResult(nil)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| setValueChannel.setMessageHandler(nil) |
| } |
| let getAllWithPrefixChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.getAllWithPrefix", binaryMessenger: binaryMessenger) |
| if let api = api { |
| getAllWithPrefixChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let prefixArg = args[0] as! String |
| do { |
| let result = try api.getAllWithPrefix(prefix: prefixArg) |
| reply(wrapResult(result)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| getAllWithPrefixChannel.setMessageHandler(nil) |
| } |
| let clearWithPrefixChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.UserDefaultsApi.clearWithPrefix", binaryMessenger: binaryMessenger) |
| if let api = api { |
| clearWithPrefixChannel.setMessageHandler { message, reply in |
| let args = message as! [Any] |
| let prefixArg = args[0] as! String |
| do { |
| try api.clearWithPrefix(prefix: prefixArg) |
| reply(wrapResult(nil)) |
| } catch { |
| reply(wrapError(error)) |
| } |
| } |
| } else { |
| clearWithPrefixChannel.setMessageHandler(nil) |
| } |
| } |
| } |