OCPredefinedFuncWrapResult constructor
OCPredefinedFuncWrapResult()
Implementation
OCPredefinedFuncWrapResult()
: super(
functionName: 'wrapResult',
isCFlavor: true,
isStatic: true,
returnType:
AstMap(keyType: AstString(), valueType: AstCustomType('id')),
params: [
Variable(const AstObject(), 'result'),
Variable(AstCustomType(typeFlutterError), 'error')
],
body: (depth) {
final ret = <CodeUnit>[
OneLine(
depth: depth + 1,
body:
'NSDictionary *errorDict = (NSDictionary *)[NSNull null];'),
OneLine(depth: depth + 1, body: 'if (error) {'),
OneLine(depth: depth + 2, body: 'errorDict = @{'),
OneLine(
depth: depth + 3,
body:
'@"${Keys.errorCode}": (error.code ? error.code : [NSNull null]),'),
OneLine(
depth: depth + 3,
body:
'@"${Keys.errorMessage}": (error.message ? error.message : [NSNull null]),'),
OneLine(
depth: depth + 3,
body:
'@"${Keys.errorDetails}": (error.details ? error.details : [NSNull null]),'),
OneLine(depth: depth + 3, body: '};'),
OneLine(depth: depth + 1, body: '}'),
OneLine(depth: depth + 1, body: 'return @{'),
OneLine(
depth: depth + 2,
body:
'@"${Keys.result}": (result ? result : [NSNull null]),'),
OneLine(depth: depth + 2, body: '@"${Keys.error}": errorDict,'),
OneLine(depth: depth + 2, body: '};'),
];
return ret;
});