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.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.
      forceBox: 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();
}