Repository navigation
Closed
flutter/packages
#328Labels
has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Bug
Steps to Reproduce
- Create
pigeons/bridge.dartfile. - Add multiple HostApi classes with methods that return value (type can be different):
import 'package:pigeon/pigeon.dart';
class Response {
int result;
}
@HostApi()
abstract class BridgeApi1 {
@async
Response call();
}
@HostApi()
abstract class BridgeApi2 {
@async
Response call();
}- Generate pigeon files:
flutter pub run pigeon \
--input pigeons/bridge.dart \
--dart_out lib/pigeons/Bridge.dart \
--java_out android/app/src/main/kotlin/com/pigeons/Bridge.java \
--java_package "com.my.pigeons"
- Try to compile Android code
Expected results:
Code compiles.
Actual results:
Error is thrown:
error: interface Result is already defined in class Bridge
Versions
pigeon: 0.1.17
Generated Bridge.java
// Autogenerated from Pigeon (v0.1.17), do not edit directly.
// See also: https://pub.dev/packages/pigeon
package com.my.pigeons;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import java.util.ArrayList;
import java.util.HashMap;
/** Generated class from Pigeon. */
@SuppressWarnings("unused")
public class Bridge {
/** Generated class from Pigeon that represents data sent in messages. */
public static class Response {
private Long result;
public Long getResult() { return result; }
public void setResult(Long setterArg) { this.result = setterArg; }
HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
toMapResult.put("result", result);
return toMapResult;
}
static Response fromMap(HashMap map) {
Response fromMapResult = new Response();
Object result = map.get("result");
fromMapResult.result = (result == null) ? null : ((result instanceof Integer) ? (Integer)result : (Long)result);
return fromMapResult;
}
}
public interface Result<T> {
void success(T result);
}
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
public interface BridgeApi1 {
void call(Result<Response> result);
/** Sets up an instance of `BridgeApi1` to handle messages through the `binaryMessenger` */
static void setup(BinaryMessenger binaryMessenger, BridgeApi1 api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.BridgeApi1.call", new StandardMessageCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
HashMap<String, HashMap> wrapped = new HashMap<>();
try {
api.call(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
}
catch (Exception exception) {
wrapped.put("error", wrapError(exception));
reply.reply(wrapped);
}
});
} else {
channel.setMessageHandler(null);
}
}
}
}
public interface Result<T> {
void success(T result);
}
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
public interface BridgeApi2 {
void call(Result<Response> result);
/** Sets up an instance of `BridgeApi2` to handle messages through the `binaryMessenger` */
static void setup(BinaryMessenger binaryMessenger, BridgeApi2 api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.BridgeApi2.call", new StandardMessageCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
HashMap<String, HashMap> wrapped = new HashMap<>();
try {
api.call(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
}
catch (Exception exception) {
wrapped.put("error", wrapError(exception));
reply.reply(wrapped);
}
});
} else {
channel.setMessageHandler(null);
}
}
}
}
private static HashMap wrapError(Exception exception) {
HashMap<String, Object> errorMap = new HashMap<>();
errorMap.put("message", exception.toString());
errorMap.put("code", exception.getClass().getSimpleName());
errorMap.put("details", null);
return errorMap;
}
}Reacted by gaaclarke and Matej Drobnič
Metadata
Metadata
Assignees
Labels
has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Activity
iapicca commentedon Dec 13, 2020
as requested in pigeon feedback cc @gaaclarke
pedromassangocode commentedon Dec 14, 2020
Reproducible with the latest version of the package.
Important to notice that the issue is only reproducible with the
@asyncannotation!Pigeon template
Pigeon Java result
github-actions commentedon Aug 2, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.