首页 > 解决方案 > 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).

标签: dartflutter

解决方案


将 @(TRUE) 更改为 @(YES) 即可。


推荐阅读