File tree 6 files changed +63
-4
lines changed
platform_tests/android_unit_tests/android/app/src/test/java/com/example/android_unit_tests 6 files changed +63
-4
lines changed Original file line number Diff line number Diff line change
1
+ ## 3.2.6
2
+
3
+ * [ java] Fixes returning int values from FlutterApi methods that fit in 32 bits.
4
+
1
5
## 3.2.5
2
6
3
7
* [ c++] Fixes style issues in ` FlutterError ` and ` ErrorOr ` . The names and
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import 'dart:mirrors';
9
9
import 'ast.dart' ;
10
10
11
11
/// The current version of pigeon. This must match the version in pubspec.yaml.
12
- const String pigeonVersion = '3.2.5 ' ;
12
+ const String pigeonVersion = '3.2.6 ' ;
13
13
14
14
/// Read all the content from [stdin] to a String.
15
15
String readStdin () {
Original file line number Diff line number Diff line change @@ -376,7 +376,13 @@ static MessageCodec<Object> getCodec() {
376
376
} else {
377
377
const String output = 'output' ;
378
378
indent.writeln ('@SuppressWarnings("ConstantConditions")' );
379
- indent.writeln ('$returnType $output = ($returnType )channelReply;' );
379
+ if (func.returnType.baseName == 'int' ) {
380
+ indent.writeln (
381
+ '$returnType $output = channelReply == null ? null : ((Number)channelReply).longValue();' );
382
+ } else {
383
+ indent
384
+ .writeln ('$returnType $output = ($returnType )channelReply;' );
385
+ }
380
386
indent.writeln ('callback.reply($output );' );
381
387
}
382
388
});
Original file line number Diff line number Diff line change @@ -30,7 +30,16 @@ private static BinaryMessenger makeMockBinaryMessenger() {
30
30
message .position (0 );
31
31
ArrayList <Object > args =
32
32
(ArrayList <Object >) PrimitiveFlutterApi .getCodec ().decodeMessage (message );
33
- ByteBuffer replyData = PrimitiveFlutterApi .getCodec ().encodeMessage (args .get (0 ));
33
+ Object arg = args .get (0 );
34
+ if (arg instanceof Long ) {
35
+ Long longArg = (Long ) arg ;
36
+ if (longArg .intValue () == longArg .longValue ()) {
37
+ // Value fits in the Integer so gets sent as such
38
+ // https://docs.flutter.dev/development/platform-integration/platform-channels?tab=type-mappings-java-tab#codec
39
+ arg = Integer .valueOf (longArg .intValue ());
40
+ }
41
+ }
42
+ ByteBuffer replyData = PrimitiveFlutterApi .getCodec ().encodeMessage (arg );
34
43
replyData .position (0 );
35
44
reply .reply (replyData );
36
45
return null ;
@@ -54,6 +63,20 @@ public void primitiveInt() {
54
63
assertTrue (didCall [0 ]);
55
64
}
56
65
66
+ @ Test
67
+ public void primitiveLongInt () {
68
+ BinaryMessenger binaryMessenger = makeMockBinaryMessenger ();
69
+ PrimitiveFlutterApi api = new PrimitiveFlutterApi (binaryMessenger );
70
+ boolean [] didCall = {false };
71
+ api .anInt (
72
+ 1L << 50 ,
73
+ (Long result ) -> {
74
+ didCall [0 ] = true ;
75
+ assertEquals (result .longValue (), 1L << 50 );
76
+ });
77
+ assertTrue (didCall [0 ]);
78
+ }
79
+
57
80
@ Test
58
81
public void primitiveIntHostApi () {
59
82
PrimitiveHostApi mockApi = mock (PrimitiveHostApi .class );
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: pigeon
2
2
description : Code generator tool to make communication between Flutter and the host platform type-safe and easier.
3
3
repository : https://github.com/flutter/packages/tree/main/packages/pigeon
4
4
issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
5
- version : 3.2.5 # This must match the version in lib/generator_tools.dart
5
+ version : 3.2.6 # This must match the version in lib/generator_tools.dart
6
6
7
7
environment :
8
8
sdk : " >=2.12.0 <3.0.0"
Original file line number Diff line number Diff line change @@ -836,6 +836,32 @@ void main() {
836
836
expect (code, contains ('List<Long> output =' ));
837
837
});
838
838
839
+ test ('flutter int return' , () {
840
+ final Root root = Root (
841
+ apis: < Api > [
842
+ Api (name: 'Api' , location: ApiLocation .flutter, methods: < Method > [
843
+ Method (
844
+ name: 'doit' ,
845
+ returnType:
846
+ const TypeDeclaration (baseName: 'int' , isNullable: false ),
847
+ arguments: < NamedType > [],
848
+ isAsynchronous: true )
849
+ ])
850
+ ],
851
+ classes: < Class > [],
852
+ enums: < Enum > [],
853
+ );
854
+ final StringBuffer sink = StringBuffer ();
855
+ const JavaOptions javaOptions = JavaOptions (className: 'Messages' );
856
+ generateJava (javaOptions, root, sink);
857
+ final String code = sink.toString ();
858
+ expect (code, contains ('doit(Reply<Long> callback)' ));
859
+ expect (
860
+ code,
861
+ contains (
862
+ 'Long output = channelReply == null ? null : ((Number)channelReply).longValue();' ));
863
+ });
864
+
839
865
test ('host multiple args' , () {
840
866
final Root root = Root (apis: < Api > [
841
867
Api (name: 'Api' , location: ApiLocation .host, methods: < Method > [
You can’t perform that action at this time.
0 commit comments