[pigeon] Fixed void void async methods (#316)

* [pigeon] Fixed void void async methods

* format
This commit is contained in:
gaaclarke
2021-03-29 09:45:26 -07:00
committed by GitHub
parent 8d787739a6
commit e1849b61fe
3 changed files with 9 additions and 3 deletions

View File

@ -56,7 +56,9 @@ void _writeHostApi(Indent indent, Api api) {
argSignature.add('${method.argType} arg');
}
if (method.isAsynchronous) {
argSignature.add('Result<${method.returnType}> result');
final String returnType =
method.returnType == 'void' ? 'Void' : method.returnType;
argSignature.add('Result<$returnType> result');
}
indent.writeln('$returnType ${method.name}(${argSignature.join(', ')});');
}
@ -94,9 +96,11 @@ void _writeHostApi(Indent indent, Api api) {
methodArgument.add('input');
}
if (method.isAsynchronous) {
final String resultValue =
method.returnType == 'void' ? 'null' : 'result.toMap()';
methodArgument.add(
'result -> { '
'wrapped.put("${Keys.result}", result.toMap()); '
'wrapped.put("${Keys.result}", $resultValue); '
'reply.reply(wrapped); '
'}',
);

View File

@ -250,7 +250,7 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) {
}
if (func.isAsynchronous) {
if (func.returnType == 'void') {
const String callback = 'callback(error));';
const String callback = 'callback(error);';
if (func.argType == 'void') {
indent.writeScoped(
'[api ${func.name}:^(FlutterError *_Nullable error) {',

View File

@ -12,6 +12,8 @@ class Value {
abstract class Api2Host {
@async
Value calculate(Value value);
@async
void voidVoid();
}
@FlutterApi()