Skip to content

[pigeon] Allow default argument values #98448

@stuartmorgan-g

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.

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