artflutter / reactive_forms_generator

Other
89 stars 22 forks source link

Could not format because the source could not be parsed #120

Closed marcmacias96 closed 1 year ago

marcmacias96 commented 1 year ago

Frezzed Class

@freezed
@ReactiveFormAnnotation()
class Credentials with _$Credentials {
  const factory Credentials({
    @FormControlAnnotation(validators: [EmailValidator(),RequiredValidator()])
    required String email,
    @FormControlAnnotation(validators: [MinValidator(8)])
    required String password,
    @FormControlAnnotation(validators: [RequiredValidator()])
    required bool rememberMe,
  }) = _Credentials;
}

Problem

I can't add more than one validation per property in a frezzed class which generates the following error

Could not format because the source could not be parsed:

line 227, column 249 of .: Expected to find ']'.
    ╷
227 │ static FormGroup formElements(Credentials? credentials) => FormGroup({emailControlName: FormControl<String>(value: credentials?.email,validators:  [EmailValidator(),asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false),passwordControlName: FormControl<String>(value: credentials?.password,validators:  [MinValidator(8)],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false),rememberMeControlName: FormControl<bool>(value: credentials?.rememberMe,validators:  [RequiredValidator()],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false)},validators: [],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false);
    │                                                                                                                                                                                                                                                         ^
    ╵
line 227, column 181 of .: Expected to find ')'.
    ╷
227 │ static FormGroup formElements(Credentials? credentials) => FormGroup({emailControlName: FormControl<String>(value: credentials?.email,validators:  [EmailValidator(),asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false),passwordControlName: FormControl<String>(value: credentials?.password,validators:  [MinValidator(8)],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false),rememberMeControlName: FormControl<bool>(value: credentials?.rememberMe,validators:  [RequiredValidator()],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false,touched: false)},validators: [],asyncValidators: [],asyncValidatorsDebounceTime: 250,disabled: false);
    │                                                                                                                                                                                     ^
    ╵
[INFO] Running build completed, took 23.4s

Only one validator build runner work's

@freezed
@ReactiveFormAnnotation()
class Credentials with _$Credentials {
  const factory Credentials({
    @FormControlAnnotation(validators: [EmailValidator()])
    required String email,
    @FormControlAnnotation(validators: [MinValidator(8)])
    required String password,
    @FormControlAnnotation(validators: [RequiredValidator()])
    required bool rememberMe,
  }) = _Credentials;
}

[INFO] Succeeded after 24.4s with 5 outputs (133 actions)

Build runner don't work without freezzed

@ReactiveFormAnnotation()
class Credentials {
  final String email;
  final String password;

  Credentials({
    @FormControlAnnotation(
      validators: [
        RequiredValidator(),
        EmailValidator(),
      ],
    ) required this.email,
    @FormControlAnnotation(
      validators: [
        RequiredValidator(),
      ],
    ) required this.password,
  });
}

Error

@ReactiveFormAnnotation()
class Credentials {
  final String email;
  final String password;

  Credentials({
    @FormControlAnnotation(
      validators: [
        RequiredValidator(),
        EmailValidator(),
      ],
    ) required this.email,
    @FormControlAnnotation(
      validators: [
        RequiredValidator(),
      ],
    ) required this.password,
  });
}
vasilich6107 commented 1 year ago

check 2.0.1 and 3.0.1 for the fix

github-actions[bot] commented 1 year ago

Hi @marcmacias96! Your issue has been closed. If we were helpful don't forget to star the repo.

Please check our reactive_forms widget section https://github.com/artflutter/reactive_forms_widgets

We would appreciate sponsorship subscription or one time donation https://github.com/sponsors/artflutter