Skip to content

[pigeon] Reduce duplication in generated Dart code. #101446

Closed
flutter/packages
#11114

Description

@stuartmorgan-g

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

Activity

  1. added
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    P1High-priority issues at the top of the work list
    on Apr 6, 2022
  2. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Jan 21, 2023
  3. self-assigned this
    on Feb 26, 2026
  4. github-actions commented on Mar 14, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions