我在 Dart 和 Kotlin 中建立了一个基本的方法通道
飞镖代码
Future<void> _updateProfile() async {
try {
var result = await platform.invokeMethod('updateProfile');
print(result);
} on PlatformException catch (e) {
print('Failed to get battery level: ${e.message}');
}
setState(() {
// print('Setting state');
});
}
Kotlin 代码
MethodChannel(flutterView, channel).setMethodCallHandler { call, result ->
if(call.method == "updateProfile"){
val actualResult = updateProfile()
if (actualResult.equals("Method channel Success")) {
result.success(actualResult)
} else {
result.error("UNAVAILABLE", "Result was not what I expected", null)
}
} else {
result.notImplemented()
}
}
我想将 JSON/Map 数据传递到 Kotlin 端。我的数据如下所示:
{
"user_dob":"15 November 1997",
"user_description":"Hello there, I am a User!",
"user_gender":"Male",
"user_session":"KKDSH3G9OJKJFIHXLJXUGWIOG9UJKLJ98WHIJ"
}
如何将这些数据从 dart 传递到 kotlin?