writeFlutterApi method
void
writeFlutterApi(
- CppOptions generatorOptions,
- Root root,
- Indent indent,
- AstFlutterApi api, {
- required String dartPackageName,
override
Writes a single Flutter Api to indent
.
Implementation
@override
void writeFlutterApi(
CppOptions generatorOptions,
Root root,
Indent indent,
AstFlutterApi api, {
required String dartPackageName,
}) {
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, api.name, parameters: <String>[
'flutter::BinaryMessenger* binary_messenger',
'const std::string& message_channel_suffix',
]);
_writeFunctionDeclaration(indent, 'GetCodec',
returnType: 'const flutter::StandardMessageCodec&', isStatic: true);
for (final Method func in api.methods) {
final HostDatatype returnType =
getHostDatatype(func.returnType, _baseCppTypeForBuiltinDartType);
addDocumentationComments(
indent, func.documentationComments, _docCommentSpec);
final Iterable<String> argTypes =
func.parameters.map((NamedType arg) {
final HostDatatype hostType =
getFieldHostDatatype(arg, _baseCppTypeForBuiltinDartType);
return _flutterApiArgumentType(hostType);
});
final Iterable<String> argNames =
indexMap(func.parameters, _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_;');
indent.writeln('std::string message_channel_suffix_;');
});
}, nestCount: 0);
indent.newln();
}