Skip to content

Can{t get model with a FormGroup inside a FormArray inside a nested FormGroup #154

@fershous

Description

@fershous

Here are the models:

/// [UserProfile] model
@freezed
@ReactiveFormAnnotation()
@FormGroupAnnotation()
class UserProfile with _$UserProfile, BaseUser, NexusElement {
  const factory UserProfile({
    required String id,
    @RfControl(validators: [RequiredValidator()]) required String name,
    required UserProfileType type,
  }) = _UserProfile;

  /// Serialization
  factory UserProfile.fromJson(Map<String, dynamic> json) => _$UserProfileFromJson(json);
}

@ReactiveFormAnnotation()
@FormGroupAnnotation()
class UserProfileType {
  UserProfileType({
    @FormArrayAnnotation() required this.permissions,
    @FormControlAnnotation() required this.value,
  });

  final List<PermissionEntity> permissions;
  final int value;
}

@ReactiveFormAnnotation()
@FormGroupAnnotation()
class PermissionEntity {
  PermissionEntity({
    @FormControlAnnotation() required this.permission,
    @FormControlAnnotation() required this.value,
  });

  final ProfilePermissionsEnum permission;
  final bool value;
}

The problem is that the PermissionEntity is being created as a FormControl<Map<String, Object?>> and it won't read it as a FormGroup . Unless I'm doing something wrong, I think there's something bad happening.

I have used FormArrays as FormGroups and indeed it read it as FormControl<Map<String, Object?>> but it works if I just cast it as FormGroup maybe a cast is missing when getting the value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions