writeFlutterApi method

  1. @override
void writeFlutterApi(
  1. ObjcOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Api api, {
  5. required String dartPackageName,
})
override

Writes a single Flutter Api to indent.

Implementation

@override
void writeFlutterApi(
  ObjcOptions generatorOptions,
  Root root,
  Indent indent,
  Api api, {
  required String dartPackageName,
}) {
  indent.writeln(
      '$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.');
  indent.writeln(
      'NSObject<FlutterMessageCodec> *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);');
  indent.newln();
  final String apiName = _className(generatorOptions.prefix, api.name);
  addDocumentationComments(
      indent, api.documentationComments, _docCommentSpec);

  indent.writeln('@interface $apiName : NSObject');
  indent.writeln(
      '- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;');
  indent.writeln(
      '- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger messageChannelSuffix:(nullable NSString *)messageChannelSuffix;');
  for (final Method func in api.methods) {
    final _ObjcType returnType = _objcTypeForDartType(
      generatorOptions.prefix, func.returnType,
      // Nullability is required since the return must be nil if NSError is set.
      forceNullability: true,
    );
    final String callbackType =
        _callbackForType(func.returnType, returnType, generatorOptions);
    addDocumentationComments(
        indent, func.documentationComments, _docCommentSpec);

    indent.writeln('${_makeObjcSignature(
      func: func,
      options: generatorOptions,
      returnType: 'void',
      lastArgName: 'completion',
      lastArgType: callbackType,
    )};');
  }
  indent.writeln('@end');
  indent.newln();
}