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

Support Freezed classes #3

Closed
lucasbstn opened this issue Aug 11, 2021 · 12 comments
Closed

Support Freezed classes #3

lucasbstn opened this issue Aug 11, 2021 · 12 comments

Comments

@lucasbstn
Copy link

lucasbstn commented Aug 11, 2021

Hello,

I'll start by saying I love the idea of the package. However, I use Freezed to generate my data classes.
I tried adding the generator to a freezed class but the properties of factory constructors don't seem to get picked up.

As an example here is the freezed class:

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:reactive_forms_annotations/reactive_forms_annotations.dart';

part 'test.g.dart';
part 'test.freezed.dart';

@freezed
@ReactiveFormAnnotation()
class Test with _$Test {
  const factory Test({
    @FormControlAnnotation() String? id,
    @FormControlAnnotation() String? name,
    @FormControlAnnotation() double? year,
  }) = _Test;

  factory Test.fromJson(Map<String, dynamic> json) => _$TestFromJson(json);
}

The expected behaviour would be something like:

class TestForm {
  TestForm(this.test, this.form, this.path) {}

  final Test test;

  final FormGroup form;

  final String? path;

  Test get model => Test();
  FormGroup formElements() => FormGroup({
        'id': FormControl<String>(),
        'name': FormControl<String>(),
        'year': FormControl<double>(),
      },
          validators: [],
          asyncValidators: [],
          asyncValidatorsDebounceTime: 250,
          disabled: false);
}

Would you consider adding support for this in the near future ?

@vasilich6107
Copy link
Contributor

vasilich6107 commented Aug 13, 2021

Wow)
This looks challenging

@vasilich6107
Copy link
Contributor

I will try to address this issue after vacation, nearly first of september.

@vasilich6107
Copy link
Contributor

@lucasbstn chech v0.1.0 for freezed support

@vasilich6107
Copy link
Contributor

@lucasbstn did you have time to try?

@lucasbstn
Copy link
Author

Hey,

Thank you for adding support for this.
l will give it a try tomorrow and let you know !

@lucasbstn
Copy link
Author

Hi !

I just gave it a quick try and it seems to be working great.
I'll try implementing it in an actual project next week and I'll let you know if I find any issues.

Thanks again for taking the time to implement this.

@vasilich6107
Copy link
Contributor

Awesome news.
Waiting for update

@vasilich6107
Copy link
Contributor

Fixed bug for freezed private constructors in 0.2.1

@vasilich6107
Copy link
Contributor

hi @lucasbstn
any updates?

@lucasbstn
Copy link
Author

Hey,

I just started implementing, it's looking good for now. I really enjoyed the fact that it gets rid of the string based apis and I found it very useful when working with FormArrays.

I encountered one issue but I don't really think it would be worth implementing in this package, I sometimes use
JsonKey(name:"test") from the json_serializable package to rename properties, and that doesn't get picked up.

I'll continue doing some testing over the next few weeks and let you know if I find any other problems.

@vasilich6107
Copy link
Contributor

Awesome news!
You can create a separate issue to discuss JsonKey handling improvements.

@vasilich6107
Copy link
Contributor

Closing this issue for now.
If there will be any issues with freezed support fill free to reopen or create new one

@artflutter artflutter locked as resolved and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants