Skip to content

[pigeon] Support data class inheritance #117819

@stuartmorgan-g

Description

@stuartmorgan-g

For macOS file_selector I wanted to define panel options that followed the macOS panel class structure, which is that NSOpenPanel is an NSSavePanel so inherits its properties. I tried:

class SavePanelOptions {
  SavePanelOptions({
    this.directoryPath,
    this.nameFieldStringValue,
    this.prompt,
  });
  String? directoryPath;
  String? nameFieldStringValue;
  String? prompt;
}

class OpenPanelOptions extends SavePanelOptions {
  OpenPanelOptions({
    super.directoryPath,
    super.nameFieldStringValue,
    super.prompt,
    this.allowsMultipleSelection = false,
    this.canChooseDirectories = false,
    this.canChooseFiles = true,
  });
  bool allowsMultipleSelection;
  bool canChooseDirectories;
  bool canChooseFiles;
}

The resulting output only has the direct properties though, not the inherited properties. For instance, the Dart is:

class SavePanelOptions {
  SavePanelOptions({
    this.directoryPath,
    this.nameFieldStringValue,
    this.prompt,
  });

  String? directoryPath;

  String? nameFieldStringValue;

  String? prompt;

  Object encode() {...}

  static SavePanelOptions decode(Object result) {...}
}

class OpenPanelOptions {
  OpenPanelOptions({
    required this.allowsMultipleSelection,
    required this.canChooseDirectories,
    required this.canChooseFiles,
  });

  bool allowsMultipleSelection;

  bool canChooseDirectories;

  bool canChooseFiles;

  Object encode() {...}

  static OpenPanelOptions decode(Object result) {...}
}

I can work around it by using composition instead of inheritance but it makes it more clunky to use on both sides.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectp: 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