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

Getters are included in generated mapping #84

Open
petrnymsa opened this issue Feb 27, 2023 · 0 comments · May be fixed by #83
Open

Getters are included in generated mapping #84

petrnymsa opened this issue Feb 27, 2023 · 0 comments · May be fixed by #83

Comments

@petrnymsa
Copy link

Often classes contains getters without explicit setter (computed getter,...). In such case, generated code tries to assign value to them.

Run smartstruct 1.4.0 against this mapper:

class GetterTarget {
  final String name;
  final int age;

  int foo = 0;

  GetterTarget({
    required this.name,
    required this.age,
  });

  List<Object?> get props => [name, age];

  bool get sample => false;
}

class GetterSource {
  final String name;
  final int age;

  int foo = 1;

  GetterSource({
    required this.name,
    required this.age,
  });

  List<Object?> get props => [name, age];

  bool get sample => true;
}

@Mapper()
abstract class GetterMapper {
  GetterTarget fromModel(GetterSource source);
}

Generated mapping

class GetterMapperImpl extends GetterMapper {
  GetterMapperImpl() : super();

  @override
  GetterTarget fromModel(GetterSource source) {
    final gettertarget = GetterTarget(
      name: source.name,
      age: source.age,
    );
    gettertarget.foo = source.foo;
     // NO SETTER !
    gettertarget.props = source.props.map((e) => e).toList();

   // NO SETTER !
    gettertarget.sample = source.sample;
    return gettertarget;
  }
}

This can happen alot if project uses Equatable, where props, stringify and hashCode is used.

@petrnymsa petrnymsa linked a pull request Feb 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant