writeEventChannelApi method

  1. @override
void writeEventChannelApi(
  1. DartOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. AstEventChannelApi api, {
  5. required String dartPackageName,
})
override

Writes a single event channel Api to indent.

Implementation

@override
void writeEventChannelApi(
  DartOptions generatorOptions,
  Root root,
  Indent indent,
  AstEventChannelApi api, {
  required String dartPackageName,
}) {
  indent.newln();
  addDocumentationComments(
      indent, api.documentationComments, _docCommentSpec);
  for (final Method func in api.methods) {
    indent.format('''
    Stream<${func.returnType.baseName}> ${func.name}(${_getMethodParameterSignature(func.parameters, addTrailingComma: true)} {String instanceName = ''}) {
      if (instanceName.isNotEmpty) {
        instanceName = '.\$instanceName';
      }
      const EventChannel ${func.name}Channel =
          EventChannel('${makeChannelName(api, func, dartPackageName)}', $_pigeonMethodChannelCodec);
      return ${func.name}Channel.receiveBroadcastStream().map((dynamic event) {
        return event as ${func.returnType.baseName};
      });
    }
  ''');
  }
}