-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Closed
flutter/packages
#11114Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
The reply handling in generated Dart code is extremely repetitive; every method contains this logic, verbatim:
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
}
See https://github.com/flutter/plugins/blob/709b3a887e76d8851112a2c29d9407727c0db8f2/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.pigeon.dart for an example; it's a 1500 line file and a third of those lines are copies of this logic.
It can be trivial extracted to a void _validateReply(Map<Object?, Object>? reply) helper (and the final else { return ... } just replaced with return ... since there's no need for an else when throwing), dramatically reducing the amount of generated code.
/cc @gaaclarke
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team