mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 01:33:59 +08:00
[pigeon] Minor Obj-C simplification (#1980)
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
## NEXT
|
## 3.0.4
|
||||||
|
|
||||||
|
* [objc] Simplified some code output, including avoiding Xcode warnings about
|
||||||
|
using `NSNumber*` directly as boolean value.
|
||||||
* [tests] Moved test script to enable CI.
|
* [tests] Moved test script to enable CI.
|
||||||
|
|
||||||
## 3.0.3
|
## 3.0.3
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||||
const String pigeonVersion = '3.0.3';
|
const String pigeonVersion = '3.0.4';
|
||||||
|
|
||||||
/// Read all the content from [stdin] to a String.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
|
@ -572,7 +572,7 @@ String _dictValue(
|
|||||||
} else if (enumNames.contains(field.type.baseName)) {
|
} else if (enumNames.contains(field.type.baseName)) {
|
||||||
return '@(self.${field.name})';
|
return '@(self.${field.name})';
|
||||||
} else {
|
} else {
|
||||||
return '(self.${field.name} ? self.${field.name} : [NSNull null])';
|
return '(self.${field.name} ?: [NSNull null])';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,8 +761,7 @@ void _writeFlutterApiSource(Indent indent, ObjcOptions options, Api api) {
|
|||||||
if (func.arguments.isEmpty) {
|
if (func.arguments.isEmpty) {
|
||||||
sendArgument = 'nil';
|
sendArgument = 'nil';
|
||||||
} else {
|
} else {
|
||||||
String makeVarOrNSNullExpression(String x) =>
|
String makeVarOrNSNullExpression(String x) => '$x ?: [NSNull null]';
|
||||||
'($x == nil) ? [NSNull null] : $x';
|
|
||||||
sendArgument = '@[${argNames.map(makeVarOrNSNullExpression).join(', ')}]';
|
sendArgument = '@[${argNames.map(makeVarOrNSNullExpression).join(', ')}]';
|
||||||
}
|
}
|
||||||
indent.write(_makeObjcSignature(
|
indent.write(_makeObjcSignature(
|
||||||
@ -838,13 +837,13 @@ static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error)
|
|||||||
\tNSDictionary *errorDict = (NSDictionary *)[NSNull null];
|
\tNSDictionary *errorDict = (NSDictionary *)[NSNull null];
|
||||||
\tif (error) {
|
\tif (error) {
|
||||||
\t\terrorDict = @{
|
\t\terrorDict = @{
|
||||||
\t\t\t\t@"${Keys.errorCode}": (error.code ? error.code : [NSNull null]),
|
\t\t\t\t@"${Keys.errorCode}": (error.code ?: [NSNull null]),
|
||||||
\t\t\t\t@"${Keys.errorMessage}": (error.message ? error.message : [NSNull null]),
|
\t\t\t\t@"${Keys.errorMessage}": (error.message ?: [NSNull null]),
|
||||||
\t\t\t\t@"${Keys.errorDetails}": (error.details ? error.details : [NSNull null]),
|
\t\t\t\t@"${Keys.errorDetails}": (error.details ?: [NSNull null]),
|
||||||
\t\t\t\t};
|
\t\t\t\t};
|
||||||
\t}
|
\t}
|
||||||
\treturn @{
|
\treturn @{
|
||||||
\t\t\t@"${Keys.result}": (result ? result : [NSNull null]),
|
\t\t\t@"${Keys.result}": (result ?: [NSNull null]),
|
||||||
\t\t\t@"${Keys.error}": errorDict,
|
\t\t\t@"${Keys.error}": errorDict,
|
||||||
\t\t\t};
|
\t\t\t};
|
||||||
}''');
|
}''');
|
||||||
@ -908,12 +907,13 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
|||||||
void writeToMap() {
|
void writeToMap() {
|
||||||
indent.write('- (NSDictionary *)toMap ');
|
indent.write('- (NSDictionary *)toMap ');
|
||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '}', () {
|
||||||
indent.write('return [NSDictionary dictionaryWithObjectsAndKeys:');
|
indent.write('return');
|
||||||
for (final NamedType field in klass.fields) {
|
indent.scoped(' @{', '};', () {
|
||||||
indent.add(_dictValue(classNames, enumNames, field) +
|
for (final NamedType field in klass.fields) {
|
||||||
', @"${field.name}", ');
|
indent.writeln(
|
||||||
}
|
'@"${field.name}" : ${_dictValue(classNames, enumNames, field)},');
|
||||||
indent.addln('nil];');
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ name: pigeon
|
|||||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||||
version: 3.0.3 # This must match the version in lib/generator_tools.dart
|
version: 3.0.4 # This must match the version in lib/generator_tools.dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
@ -1507,7 +1507,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
code,
|
code,
|
||||||
contains(
|
contains(
|
||||||
'[channel sendMessage:@[(arg_x == nil) ? [NSNull null] : arg_x, (arg_y == nil) ? [NSNull null] : arg_y] reply:'));
|
'[channel sendMessage:@[arg_x ?: [NSNull null], arg_y ?: [NSNull null]] reply:'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user