writeFlutterApi method
void
writeFlutterApi(
- CppOptions generatorOptions,
- Root root,
- Indent indent,
- Api api, {
- required String dartPackageName,
override
Writes a single Flutter Api to indent
.
Implementation
@override
void writeFlutterApi(
CppOptions generatorOptions,
Root root,
Indent indent,
Api api, {
required String dartPackageName,
}) {
assert(api.location == ApiLocation.flutter);
if (getCodecClasses(api, root).isNotEmpty) {
_writeCodec(generatorOptions, root, indent, api);
}
const List<String> generatedMessages = <String>[
' Generated class from Pigeon that represents Flutter messages that can be called from C++.'
];
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
generatorComments: generatedMessages);
indent.write('class ${api.name} ');
indent.addScoped('{', '};', () {
_writeAccessBlock(indent, _ClassAccess.public, () {
_writeFunctionDeclaration(indent, api.name,
parameters: <String>['flutter::BinaryMessenger* binary_messenger']);
_writeFunctionDeclaration(indent, 'GetCodec',
returnType: 'const flutter::StandardMessageCodec&', isStatic: true);
for (final Method func in api.methods) {
final HostDatatype returnType = getHostDatatype(func.returnType,
root.classes, root.enums, _baseCppTypeForBuiltinDartType);
addDocumentationComments(
indent, func.documentationComments, _docCommentSpec);
final Iterable<String> argTypes = func.arguments.map((NamedType arg) {
final HostDatatype hostType = getFieldHostDatatype(
arg, root.classes, root.enums, _baseCppTypeForBuiltinDartType);
return _flutterApiArgumentType(hostType);
});
final Iterable<String> argNames =
indexMap(func.arguments, _getArgumentName);
final List<String> parameters = <String>[
...map2(argTypes, argNames, (String x, String y) => '$x $y'),
..._flutterApiCallbackParameters(returnType),
];
_writeFunctionDeclaration(indent, _makeMethodName(func),
returnType: _voidType, parameters: parameters);
}
});
indent.addScoped(' private:', null, () {
indent.writeln('flutter::BinaryMessenger* binary_messenger_;');
});
}, nestCount: 0);
indent.newln();
}