4
4
// Autogenerated from Pigeon, do not edit directly.
5
5
// See also: https://pub.dev/packages/pigeon
6
6
7
-
8
7
import android.util.Log
9
8
import io.flutter.plugin.common.BasicMessageChannel
10
9
import io.flutter.plugin.common.BinaryMessenger
@@ -19,33 +18,31 @@ private fun wrapResult(result: Any?): List<Any?> {
19
18
20
19
private fun wrapError (exception : Throwable ): List <Any ?> {
21
20
if (exception is FlutterError ) {
22
- return listOf (
23
- exception.code,
24
- exception.message,
25
- exception.details
26
- )
21
+ return listOf (exception.code, exception.message, exception.details)
27
22
} else {
28
23
return listOf (
29
- exception.javaClass.simpleName,
30
- exception.toString(),
31
- " Cause: " + exception.cause + " , Stacktrace: " + Log .getStackTraceString(exception)
32
- )
24
+ exception.javaClass.simpleName,
25
+ exception.toString(),
26
+ " Cause: " + exception.cause + " , Stacktrace: " + Log .getStackTraceString(exception))
33
27
}
34
28
}
35
29
36
30
private fun createConnectionError (channelName : String ): FlutterError {
37
- return FlutterError (" channel-error" , " Unable to establish connection on channel: '$channelName '." , " " )}
31
+ return FlutterError (
32
+ " channel-error" , " Unable to establish connection on channel: '$channelName '." , " " )
33
+ }
38
34
39
35
/* *
40
36
* Error class for passing custom error details to Flutter via a thrown PlatformException.
37
+ *
41
38
* @property code The error code.
42
39
* @property message The error message.
43
40
* @property details The error details. Must be a datatype supported by the api codec.
44
41
*/
45
- class FlutterError (
46
- val code : String ,
47
- override val message : String? = null ,
48
- val details : Any? = null
42
+ class FlutterError (
43
+ val code : String ,
44
+ override val message : String? = null ,
45
+ val details : Any? = null
49
46
) : Throwable()
50
47
51
48
enum class Code (val raw : Int ) {
@@ -60,12 +57,11 @@ enum class Code(val raw: Int) {
60
57
}
61
58
62
59
/* * Generated class from Pigeon that represents data sent in messages. */
63
- data class MessageData (
64
- val name : String? = null ,
65
- val description : String? = null ,
66
- val code : Code ,
67
- val data : Map <String ?, String ?>
68
-
60
+ data class MessageData (
61
+ val name : String? = null ,
62
+ val description : String? = null ,
63
+ val code : Code ,
64
+ val data : Map <String ?, String ?>
69
65
) {
70
66
companion object {
71
67
@Suppress(" UNCHECKED_CAST" )
@@ -77,12 +73,13 @@ data class MessageData (
77
73
return MessageData (name, description, code, data)
78
74
}
79
75
}
76
+
80
77
fun toList (): List <Any ?> {
81
78
return listOf<Any ?>(
82
- name,
83
- description,
84
- code.raw,
85
- data,
79
+ name,
80
+ description,
81
+ code.raw,
82
+ data,
86
83
)
87
84
}
88
85
}
@@ -92,14 +89,13 @@ private object ExampleHostApiCodec : StandardMessageCodec() {
92
89
override fun readValueOfType (type : Byte , buffer : ByteBuffer ): Any? {
93
90
return when (type) {
94
91
128 .toByte() -> {
95
- return (readValue(buffer) as ? List <Any ?>)?.let {
96
- MessageData .fromList(it)
97
- }
92
+ return (readValue(buffer) as ? List <Any ?>)?.let { MessageData .fromList(it) }
98
93
}
99
94
else -> super .readValueOfType(type, buffer)
100
95
}
101
96
}
102
- override fun writeValue (stream : ByteArrayOutputStream , value : Any? ) {
97
+
98
+ override fun writeValue (stream : ByteArrayOutputStream , value : Any? ) {
103
99
when (value) {
104
100
is MessageData -> {
105
101
stream.write(128 )
@@ -113,19 +109,23 @@ private object ExampleHostApiCodec : StandardMessageCodec() {
113
109
/* * Generated interface from Pigeon that represents a handler of messages from Flutter. */
114
110
interface ExampleHostApi {
115
111
fun getHostLanguage (): String
112
+
116
113
fun add (a : Long , b : Long ): Long
114
+
117
115
fun sendMessage (message : MessageData , callback : (Result <Boolean >) -> Unit )
118
116
119
117
companion object {
120
118
/* * The codec used by ExampleHostApi. */
121
- val codec: MessageCodec <Any ?> by lazy {
122
- ExampleHostApiCodec
123
- }
119
+ val codec: MessageCodec <Any ?> by lazy { ExampleHostApiCodec }
124
120
/* * Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */
125
121
@Suppress(" UNCHECKED_CAST" )
126
122
fun setUp (binaryMessenger : BinaryMessenger , api : ExampleHostApi ? ) {
127
123
run {
128
- val channel = BasicMessageChannel <Any ?>(binaryMessenger, " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage" , codec)
124
+ val channel =
125
+ BasicMessageChannel <Any ?>(
126
+ binaryMessenger,
127
+ " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage" ,
128
+ codec)
129
129
if (api != null ) {
130
130
channel.setMessageHandler { _, reply ->
131
131
var wrapped: List <Any ?>
@@ -141,7 +141,11 @@ interface ExampleHostApi {
141
141
}
142
142
}
143
143
run {
144
- val channel = BasicMessageChannel <Any ?>(binaryMessenger, " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add" , codec)
144
+ val channel =
145
+ BasicMessageChannel <Any ?>(
146
+ binaryMessenger,
147
+ " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add" ,
148
+ codec)
145
149
if (api != null ) {
146
150
channel.setMessageHandler { message, reply ->
147
151
val args = message as List <Any ?>
@@ -160,7 +164,11 @@ interface ExampleHostApi {
160
164
}
161
165
}
162
166
run {
163
- val channel = BasicMessageChannel <Any ?>(binaryMessenger, " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage" , codec)
167
+ val channel =
168
+ BasicMessageChannel <Any ?>(
169
+ binaryMessenger,
170
+ " dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage" ,
171
+ codec)
164
172
if (api != null ) {
165
173
channel.setMessageHandler { message, reply ->
166
174
val args = message as List <Any ?>
@@ -187,26 +195,30 @@ interface ExampleHostApi {
187
195
class MessageFlutterApi (private val binaryMessenger : BinaryMessenger ) {
188
196
companion object {
189
197
/* * The codec used by MessageFlutterApi. */
190
- val codec: MessageCodec <Any ?> by lazy {
191
- StandardMessageCodec ()
192
- }
198
+ val codec: MessageCodec <Any ?> by lazy { StandardMessageCodec () }
193
199
}
200
+
194
201
fun flutterMethod (aStringArg : String? , callback : (Result <String >) -> Unit ) {
195
202
val channelName = " dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod"
196
203
val channel = BasicMessageChannel <Any ?>(binaryMessenger, channelName, codec)
197
204
channel.send(listOf (aStringArg)) {
198
205
if (it is List <* >) {
199
206
if (it.size > 1 ) {
200
- callback(Result .failure(FlutterError (it[0 ] as String , it[1 ] as String , it[2 ] as String? )));
207
+ callback(Result .failure(FlutterError (it[0 ] as String , it[1 ] as String , it[2 ] as String? )))
201
208
} else if (it[0 ] == null ) {
202
- callback(Result .failure(FlutterError (" null-error" , " Flutter api returned null value for non-null return value." , " " )));
209
+ callback(
210
+ Result .failure(
211
+ FlutterError (
212
+ " null-error" ,
213
+ " Flutter api returned null value for non-null return value." ,
214
+ " " )))
203
215
} else {
204
216
val output = it[0 ] as String
205
- callback(Result .success(output));
217
+ callback(Result .success(output))
206
218
}
207
219
} else {
208
- callback(Result .failure(createConnectionError(channelName)));
209
- }
220
+ callback(Result .failure(createConnectionError(channelName)))
221
+ }
210
222
}
211
223
}
212
224
}
0 commit comments