schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
135 stars 20 forks source link

copyWith on Lists results in The getter 'copyWith' isn't defined for the type ... #175

Closed JohnGalt1717 closed 4 months ago

JohnGalt1717 commented 4 months ago

I have the following:

part 'messagedto.mapper.dart';

@MappableClass()
class MessageDto with MessageDtoMappable {
  final TopicRefDto topic;
  final String parentTopicName;
  final String? subject;
  final String body;
  final List<MessageContactDto> contacts;
  final DateTime timestamp;
  final String? inResponseMessageToId;

  MessageDto({
    required this.topic,
    required this.parentTopicName,
    this.subject,
    required this.body,
    required this.contacts,
    required this.timestamp,
    this.inResponseMessageToId,
  });
}

Which generates this:

 (rest)
  @override
  ListCopyWith<$R, MessageContactDto,
          MessageContactDtoCopyWith<$R, MessageContactDto, MessageContactDto>>
      get contacts => ListCopyWith($value.contacts,
          (v, t) => v.copyWith.$chain(t), (v) => call(contacts: v));

which throws an error:


The getter 'copyWith' isn't defined for the type 'MessageContactDto'.
Try importing the library that defines 'copyWith', correcting the name to the name of an existing getter, or defining a getter or field named 'copyWith'.

MessageContactDto is defined like this:

part 'messagecontactdto.mapper.dart';

@MappableClass()
class MessageContactDto {
  TopicRefDto contact;
  String? reaction;
  bool flagged;
  bool pinned;
  bool read;
  bool creator;
  CommunicationProtocols source;

  MessageContactDto({
    required this.contact,
    this.reaction,
    required this.flagged,
    required this.pinned,
    this.read = false,
    required this.creator,
    required this.source,
  });
}

Which generates (in part):

  MessageContactDtoCopyWith<MessageContactDto, MessageContactDto,
          MessageContactDto>
      get copyWith => _MessageContactDtoCopyWithImpl(
          this as MessageContactDto, $identity, $identity);

Why is it throwing the error? It appears to be correct and should be doing a deep copy on the list?

schultek commented 4 months ago

You're missing the mixin on messagecontactdto class

JohnGalt1717 commented 4 months ago

Thanks. head bang