Pigeon: Definitions for showCastDialog
- Generated Pigeons for `HostApis` in Android and iOS
This commit is contained in:
parent
1b689bc8d6
commit
4e56530e63
5 changed files with 63 additions and 0 deletions
|
|
@ -73,6 +73,7 @@ public class HostApis {
|
|||
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
|
||||
public interface CastApi {
|
||||
void sendMessage(CastMessage message);
|
||||
void showCastDialog();
|
||||
|
||||
/** The codec used by CastApi. */
|
||||
static MessageCodec<Object> getCodec() {
|
||||
|
|
@ -105,6 +106,25 @@ public class HostApis {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ NSObject<FlutterMessageCodec> *CastApiGetCodec(void);
|
|||
|
||||
@protocol CastApi
|
||||
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
|
||||
- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||
@end
|
||||
|
||||
extern void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api);
|
||||
|
|
|
|||
|
|
@ -119,4 +119,22 @@ void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi>
|
|||
[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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,4 +84,27 @@ class CastApi {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ class CastMessage {
|
|||
@HostApi()
|
||||
abstract class CastApi {
|
||||
void sendMessage(CastMessage message);
|
||||
void showCastDialog();
|
||||
}
|
||||
Loading…
Reference in a new issue