mirror of
https://github.com/flutter/packages.git
synced 2025-07-03 09:08:54 +08:00
[pigeon] Fix Kotlin generated sync host api error (#2693)
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 4.2.4
|
||||
|
||||
* [kotlin] Fixes Kotlin generated sync host api error.
|
||||
|
||||
## 4.2.3
|
||||
|
||||
* [java] Adds assert `args != null`.
|
||||
|
@ -9,7 +9,7 @@ import 'dart:mirrors';
|
||||
import 'ast.dart';
|
||||
|
||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '4.2.3';
|
||||
const String pigeonVersion = '4.2.4';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
@ -250,7 +250,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
|
||||
}
|
||||
}, addTrailingNewline: false);
|
||||
indent.add(' catch (exception: Error) ');
|
||||
indent.scoped('{', '', () {
|
||||
indent.scoped('{', '}', () {
|
||||
indent.writeln(
|
||||
'wrapped["${Keys.error}"] = wrapError(exception)');
|
||||
if (method.isAsynchronous) {
|
||||
@ -262,7 +262,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
|
||||
}
|
||||
});
|
||||
}, addTrailingNewline: false);
|
||||
indent.scoped('} else {', '}', () {
|
||||
indent.scoped(' else {', '}', () {
|
||||
indent.writeln('channel.setMessageHandler(null)');
|
||||
});
|
||||
});
|
||||
|
@ -2,7 +2,7 @@ name: pigeon
|
||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||
version: 4.2.3 # This must match the version in lib/generator_tools.dart
|
||||
version: 4.2.4 # This must match the version in lib/generator_tools.dart
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
@ -126,6 +126,23 @@ void main() {
|
||||
expect(code, contains('interface Api'));
|
||||
expect(code, contains('fun doSomething(input: Input): Output'));
|
||||
expect(code, contains('channel.setMessageHandler'));
|
||||
expect(code, contains('''
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val wrapped = hashMapOf<String, Any?>()
|
||||
try {
|
||||
val args = message as List<Any?>
|
||||
val inputArg = args[0] as Input
|
||||
wrapped["result"] = api.doSomething(inputArg)
|
||||
} catch (exception: Error) {
|
||||
wrapped["error"] = wrapError(exception)
|
||||
}
|
||||
reply.reply(wrapped)
|
||||
}
|
||||
} else {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
'''));
|
||||
});
|
||||
|
||||
test('all the simple datatypes header', () {
|
||||
|
Reference in New Issue
Block a user