mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +08:00
[pigeon] reved pigeon, tweaked contributors changes before publish (#304)
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
## 0.1.22
|
||||||
|
|
||||||
|
* Java code generator enhancements:
|
||||||
|
* Added linter tests to CI.
|
||||||
|
* Fixed some linter issues in the Java code.
|
||||||
|
|
||||||
## 0.1.21
|
## 0.1.21
|
||||||
|
|
||||||
* Fixed decode method on generated Flutter classes that use null-safety and have
|
* Fixed decode method on generated Flutter classes that use null-safety and have
|
||||||
|
@ -68,6 +68,48 @@ channels supports
|
|||||||
|
|
||||||
Note: Generics for List and Map aren't supported yet.
|
Note: Generics for List and Map aren't supported yet.
|
||||||
|
|
||||||
|
## Asynchronous Handlers
|
||||||
|
|
||||||
|
By default Pigeon will generate synchronous handlers for messages. If you want
|
||||||
|
to be able to respond to a message asynchronously you can use the `@async`
|
||||||
|
annotation as of version 0.1.20.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
class Value {
|
||||||
|
int number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostApi()
|
||||||
|
abstract class Api2Host {
|
||||||
|
@async
|
||||||
|
Value calculate(Value value);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Generates:
|
||||||
|
|
||||||
|
```objc
|
||||||
|
// Objc
|
||||||
|
@protocol Api2Host
|
||||||
|
-(void)calculate:(nullable Value *)input
|
||||||
|
completion:(void(^)(Value *_Nullable, FlutterError *_Nullable))completion;
|
||||||
|
@end
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Java
|
||||||
|
public interface Result<T> {
|
||||||
|
void success(T result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
|
||||||
|
public interface Api2Host {
|
||||||
|
void calculate(Value arg, Result<Value> result);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Feedback
|
## Feedback
|
||||||
|
|
||||||
File an issue in [flutter/flutter](https://github.com/flutter/flutter) with the
|
File an issue in [flutter/flutter](https://github.com/flutter/flutter) with the
|
||||||
|
@ -120,7 +120,7 @@ A downloadable example of using Pigeon to create a Flutter Plugin with Swift and
|
|||||||
Kotlin can be found at
|
Kotlin can be found at
|
||||||
[gaaclarke/flutter_plugin_example](https://github.com/gaaclarke/pigeon_plugin_example).
|
[gaaclarke/flutter_plugin_example](https://github.com/gaaclarke/pigeon_plugin_example).
|
||||||
|
|
||||||
## Swift Add-to-app Example
|
## Swift / Kotlin Add-to-app Example
|
||||||
|
|
||||||
A full example of using Pigeon for add-to-app with Swift on iOS can be found at
|
A full example of using Pigeon for add-to-app with Swift on iOS can be found at
|
||||||
[gaaclarke/GiantsA2A](https://github.com/gaaclarke/GiantsA2A).
|
[samples/add_to_app/books](https://github.com/flutter/samples/tree/master/add_to_app/books).
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||||
const String pigeonVersion = '0.1.21';
|
const String pigeonVersion = '0.1.22';
|
||||||
|
|
||||||
/// Read all the content from [stdin] to a String.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
|
@ -15,7 +15,7 @@ const Map<String, String> _javaTypeForDartTypeMap = <String, String>{
|
|||||||
'Int64List': 'long[]',
|
'Int64List': 'long[]',
|
||||||
'Float64List': 'double[]',
|
'Float64List': 'double[]',
|
||||||
'List': 'List<Object>',
|
'List': 'List<Object>',
|
||||||
'Map': 'Map<String, Object>',
|
'Map': 'Map<Object, Object>',
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Options that control how Java code will be generated.
|
/// Options that control how Java code will be generated.
|
||||||
@ -169,38 +169,18 @@ void _writeFlutterApi(Indent indent, Api api) {
|
|||||||
if (func.argType != 'void') {
|
if (func.argType != 'void') {
|
||||||
indent.writeln('Map<String, Object> inputMap = argInput.toMap();');
|
indent.writeln('Map<String, Object> inputMap = argInput.toMap();');
|
||||||
}
|
}
|
||||||
indent.write('if (callback != null)');
|
indent.write('channel.send($sendArgument, channelReply -> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '});', () {
|
||||||
indent.write('channel.send($sendArgument, channelReply -> ');
|
if (func.returnType == 'void') {
|
||||||
indent.scoped('{', '});', () {
|
indent.writeln('callback.reply(null);');
|
||||||
if (func.returnType == 'void') {
|
} else {
|
||||||
indent.writeln('callback.reply(null);');
|
indent.writeln('Map outputMap = (Map)channelReply;');
|
||||||
} else {
|
indent.writeln('@SuppressWarnings("ConstantConditions")');
|
||||||
indent.writeln('Map outputMap = (Map)channelReply;');
|
indent.writeln(
|
||||||
indent.writeln('@SuppressWarnings("ConstantConditions")');
|
'${func.returnType} output = ${func.returnType}.fromMap(outputMap);');
|
||||||
indent.writeln(
|
indent.writeln('callback.reply(output);');
|
||||||
'${func.returnType} output = ${func.returnType}.fromMap(outputMap);');
|
}
|
||||||
indent.writeln('callback.reply(output);');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
indent.write(' else ');
|
|
||||||
indent.scoped('{', '}', () {
|
|
||||||
indent.writeln('channel.send($sendArgument, null);');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (func.argType == 'void') {
|
|
||||||
indent.write('public void ${func.name}() ');
|
|
||||||
} else {
|
|
||||||
indent.write('public void ${func.name}(${func.argType} argInput) ');
|
|
||||||
}
|
|
||||||
indent.scoped('{', '}', () {
|
|
||||||
if (func.argType == 'void') {
|
|
||||||
indent.writeln('${func.name}(null);');
|
|
||||||
} else {
|
|
||||||
indent.writeln('${func.name}(argInput, null);');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: pigeon
|
name: pigeon
|
||||||
version: 0.1.21 # This must match the version in lib/generator_tools.dart
|
version: 0.1.22 # This must match the version in lib/generator_tools.dart
|
||||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||||
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
|
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -124,7 +124,7 @@ fi
|
|||||||
pub get
|
pub get
|
||||||
dart analyze bin
|
dart analyze bin
|
||||||
dart analyze lib
|
dart analyze lib
|
||||||
pub run test test/
|
dart --no-sound-null-safety test
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Execute without arguments test
|
# Execute without arguments test
|
||||||
|
@ -257,7 +257,7 @@ void main() {
|
|||||||
generateJava(javaOptions, root, sink);
|
generateJava(javaOptions, root, sink);
|
||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(code, contains('public static class Foobar'));
|
expect(code, contains('public static class Foobar'));
|
||||||
expect(code, contains('private Map<String, Object> field1;'));
|
expect(code, contains('private Map<Object, Object> field1;'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gen nested', () {
|
test('gen nested', () {
|
||||||
|
Reference in New Issue
Block a user