Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when generating copywith for class with private fields #85

Open
haidarmehsen opened this issue Jul 13, 2023 · 0 comments
Open

Fails when generating copywith for class with private fields #85

haidarmehsen opened this issue Jul 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@haidarmehsen
Copy link

I have this class

@CopyWith(
  constructor: '_',
  skipFields: true,
)
class AppProduct {
  /// The id of the product.
  final int id;

  /// The name of the product.
  final String name;

  /// The description of the product.
  final String? description;

  /// The original price of the product.
  final double originalPrice;

  /// The discounted price of the product.
  final double? discountedPrice;

  /// The category id of the product.
  final int categoryId;

  /// The subcategory id of the product.
  final int? subcategoryId;

  /// The image URL of the product.
  final String imageURL;

  /// The type of the product.
  // ignore: invalid_annotation_target
  @JsonKey(
    fromJson: ProductType.productTypeFromProductTypeId,
    toJson: ProductType.productTypeToProductTypeId,
    name: 'productTypeId',
  )
  final ProductType productType;

  /// Whether the product is a favorite or not. This will be null if there is
  /// no user logged in.
  final bool isFavorite;

  /// The variant options of the product.
  // ignore: invalid_annotation_target
  @JsonKey(
    name: 'variants',
    fromJson: Variant.fromJsonList,
    toJson: Variant.toJsonList,
  )
  final List<Variant>? variants;

  /// Maps the id of a single-choice-option variant to the id of the selected option of that variant.
  @JsonKey(
    name: 'singleSelectionOptions',
    defaultValue: {},
    includeToJson: true,
    includeFromJson: true,
  )
  final Map<int, int> _singleSelectionOptions;

  /// Maps the id of a multiple-choice-option variant to the ids of the selected options of that variant.
  @JsonKey(
    name: 'multipleSelectionOptions',
    defaultValue: {},
    includeToJson: true,
    includeFromJson: true,
  )
  final Map<int, List<int>> _multipleSelectionOptions;

  AppProduct._(
    this._singleSelectionOptions,
    this._multipleSelectionOptions, {
    required this.id,
    required this.name,
    this.description,
    required this.originalPrice,
    this.discountedPrice,
    required this.categoryId,
    this.subcategoryId,
    required this.imageURL,
    required this.productType,
    required this.isFavorite,
    this.variants,
  }) {
    _ensureRequiredOptionsSelected();
  }
}

The IDE reports no erros in the generated code, but when trying to run the app, I get this error and the app can't start:

lib/services/api/product_management_service/app_product/app_product.g.dart:17:20: Error: An optional named parameter can't start with '_'.
    Map<int, int>? _singleSelectionOptions,
                   ^^^^^^^^^^^^^^^^^^^^^^^
lib/services/api/product_management_service/app_product/app_product.g.dart:18:26: Error: An optional named parameter can't start with '_'.
    Map<int, List<int>>? _multipleSelectionOptions,
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
lib/services/api/product_management_service/app_product/app_product.g.dart:48:13: Error: An optional named parameter can't start with '_'.
    Object? _singleSelectionOptions = const $CopyWithPlaceholder(),
            ^^^^^^^^^^^^^^^^^^^^^^^
lib/services/api/product_management_service/app_product/app_product.g.dart:49:13: Error: An optional named parameter can't start with '_'.
    Object? _multipleSelectionOptions = const $CopyWithPlaceholder(),
            ^^^^^^^^^^^^^^^^^^^^^^^^^
@numen31337 numen31337 added the bug Something isn't working label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants