Skip to content

[pigeon] Allow default argument values #98448

Closed
flutter/packages
#5355

Description

@stuartmorgan-g

(Somewhat similar to #80048, but a distinct feature.)

A common NNBD pattern for data objects in Dart is to have optional collection members be non-nullable with default empty values, to avoid having two different ways of expressing "nothing" (null vs. empty). So an object where no arguments are required would look like:

class Foo {
  Foo({
    this.aString,
    this.aDouble,
    this.aList = const List<String>[],
    this.aMap = const Map<String, int>{},
  });

  String? aString;
  double? aDouble;
  List<String> aList;
  Map<String, int> aMap;
}

Since Pigeon doesn't allow default parameter values, we currently have to make the collections nullable which makes them error-prone on the native side (we've had real bugs due to native code checking for only one type of "empty"), or we have to make the parameters required which makes them more annoying to create on the Dart side.

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    P3Issues that are less important to the Flutter project
    on Feb 14, 2022
  2. github-actions commented on Dec 2, 2023

    @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.

  3. locked as resolved and limited conversation to collaborators on Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityp: 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