Pigeon: Definitions for showCastDialog

- Generated Pigeons for `HostApis` in Android and iOS
This commit is contained in:
gianlucaparadise 2021-11-01 16:28:29 +01:00
parent 1b689bc8d6
commit 4e56530e63
5 changed files with 63 additions and 0 deletions

View file

@ -73,6 +73,7 @@ public class HostApis {
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
public interface CastApi { public interface CastApi {
void sendMessage(CastMessage message); void sendMessage(CastMessage message);
void showCastDialog();
/** The codec used by CastApi. */ /** The codec used by CastApi. */
static MessageCodec<Object> getCodec() { static MessageCodec<Object> getCodec() {
@ -105,6 +106,25 @@ public class HostApis {
channel.setMessageHandler(null); channel.setMessageHandler(null);
} }
} }
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.showCastDialog", getCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
api.showCastDialog();
wrapped.put("result", null);
}
catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
} }
} }
private static Map<String, Object> wrapError(Throwable exception) { private static Map<String, Object> wrapError(Throwable exception) {

View file

@ -20,6 +20,7 @@ NSObject<FlutterMessageCodec> *CastApiGetCodec(void);
@protocol CastApi @protocol CastApi
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; - (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
@end @end
extern void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api); extern void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api);

View file

@ -119,4 +119,22 @@ void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi>
[channel setMessageHandler:nil]; [channel setMessageHandler:nil];
} }
} }
{
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastApi.showCastDialog"
binaryMessenger:binaryMessenger
codec:CastApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api showCastDialogWithError:&error];
callback(wrapResult(nil, error));
}];
}
else {
[channel setMessageHandler:nil];
}
}
} }

View file

@ -84,4 +84,27 @@ class CastApi {
return; return;
} }
} }
Future<void> showCastDialog() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastApi.showCastDialog', codec, binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
details: null,
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
} else {
return;
}
}
} }

View file

@ -8,4 +8,5 @@ class CastMessage {
@HostApi() @HostApi()
abstract class CastApi { abstract class CastApi {
void sendMessage(CastMessage message); void sendMessage(CastMessage message);
void showCastDialog();
} }