英文:
Invalid argument: Instance of 'DateTime'
问题
I am working on a Flutter plugin, and I would like to pass from my dart
file Native Android a DateTime
parameter.
The implementation is simple:
Dart
Future<bool?> getDate(DateTime localTime) async {
return _dateChannel.invokeMethod<bool>('my_method_channel',
{'localTime': localTime});
}
Java
if (methodCall.method.equals("my_method_channel")) {
Date localTime = methodCall.argument("localTime");
System.out.println("TEST | Estimated localTime | " + localTime);
result.success(true);
}
but I am getting the following error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: Instance of 'DateTime'
Note that this is a simplification of my implementation. I understand that I could get localTime
natively, but that's not what I am looking for.
Explanation of the current situation and how to solve it.
英文:
I am working on a Flutter plugin, and I would like to pass from my dart
file Native Android a DateTime
parameter.
The implementation is simple:
Dart
Future<bool?> getDate(DateTime localTime) async {
return _dateChannel.invokeMethod<bool>('my_method_channel',
{'localTime': localTime});
}
Java
if (methodCall.method.equals("my_method_channel")) {
Date localTime = methodCall.argument("localTime");
System.out.println(
"TEST | Estimated localTime | " + localTime);
result.success(true);
}
but I am getting the following error
> [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: Instance of 'DateTime'
Note that this is a simplication of my implementation. I understand that I could get localTIme
natively but that's not what I am looking for.
Explanation of the current situation and how to solve it.
答案1
得分: 3
日期/日期时间数据类型在平台通道中不受支持。您应该将参数传递为字符串类型,然后在Java代码中进行解析。
链接:https://docs.flutter.dev/platform-integration/platform-channels?tab=type-mappings-java-tab#codec
英文:
Data type Date/Datetime is not supported for platform channel. You should pass an argument as String type and then parse it in Java code.
https://docs.flutter.dev/platform-integration/platform-channels?tab=type-mappings-java-tab#codec
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论