dart - Sending boolean value on flutter platform method channel not working correctl on iOs
问题描述
I added some iOs and Android native code to Flutter application. Function that is natively called returns a boolean value as:
Future<bool> get isOn => _channel.invokeMethod('isOn').then<bool>((d) => d);
On Android everything works correctly. In the method call handler of the channel I return a boolean as:
...
case "isAvailable":
{
result.success(myFuncThatReturnsTrueOrFalse());
break;
}
...
On iOs I have a similar handler and it always returns true:
if ([@"isOn" isEqualToString:call.method]) {
result(@(TRUE));
}
But when I run the dart isOn function on iOs i get an error about conversation of the bool and int value as:
type 'int' is not a subtype of type 'FutureOr<bool>'
I checked multiple plugins and they all do the bool stuff in the same way. Am I missing something somewhere?
I am running the latest stable flutter version (1.2.1), latest XCode (10.2.1) and the latest Android Studio (3.4).
解决方案
将 @(TRUE) 更改为 @(YES) 即可。
推荐阅读
- angular - 使用 Agm mps,我想在地图上点击角度 10 获得纬度 lng
- excel - VBA Selection.Find 返回偏移单元格
- python - 是否有一种 pathlib 方法可以在另一条路径中找到一条路径的补码?
- c++ - 如何将 cstring 作为函数参数/参数传递
- json - 嵌入json文件以在markdown中显示(GIthub pages+jekyll)
- google-cloud-platform - 无法通过付款验证激活 GCP 帐户
- python - 在 Dataframe 中跨多个列(比如两个)查找最大出现值
- javascript - 使用 javascript 创建依赖关系图
- python - 需要用数组值分解一个python字典
- angular - 导入的模块是否捆绑到 Angular 中的模块块文件中