Open fershous opened 3 months ago
So, I simple it down to this:
part 'user_profile.freezed.dart';
part 'user_profile.g.dart';
part 'user_profile.gform.dart';
/// [UserProfile] model
@freezed
@ReactiveFormAnnotation()
class UserProfile with _$UserProfile, BaseUser, NexusElement, RestrictedPermissions {
const UserProfile._();
/// Factory constructor
/// [id] - [UserProfile] id
@JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
const factory UserProfile({
required String id,
//
@FormControlAnnotation(validators: [RequiredValidator()]) required String name,
//
@JsonKey(name: "pass")
@FormControlAnnotation(validators: [RequiredValidator()])
required String passwordHash,
//
@JsonKey(
name: 'perm',
fromJson: _userProfilePermissionsFromJson,
toJson: _userProfilePermissionsToJson,
)
@FormArrayAnnotation()
required List<PermissionEntity> permissions,
//
@JsonKey(name: "bdte", fromJson: fromJsonTimestamp, toJson: toJsonTimestamp)
@FormControlAnnotation()
required DateTime? birthDate,
//
@JsonKey(name: "tel") @FormControlAnnotation() required int? phoneNumber,
}) = _UserProfile;
/// Serialization
factory UserProfile.fromJson(Map<String, dynamic> json) => _$UserProfileFromJson(json);
bool validate(String enteredPassword) {
return Crypt(passwordHash).match(enteredPassword);
}
}
@FormGroupAnnotation()
class PermissionEntity {
PermissionEntity({
@FormControlAnnotation() required this.permission,
@FormControlAnnotation() required this.value,
});
final ProfilePermissionsEnum permission;
final bool value;
}
Now if I try to print the model it works. But I can't build the ReactiveFormArrayBuilder
here's the code
ReactiveFormArray<Map<String, Object?>>(
formArray: formModel.permissionsControl,
builder: (context, formArray, child) {
return Column(
children: formModel.permissionsControl.controls
.asMap()
.map((i, deliveryPoint) {
return MapEntry(
i,
Column(
children: [
ReactiveCheckbox(
formControlName: '${i}.value',
),
],
),
);
})
.values
.toList(),
);
},
),
The problem is that it won't find the {i}.value
as there's no way to find the control because it builds the array as a normal array and not putting controls in it.
Am I doing something worng?
I'm using:
reactive_forms_generator: ^4.5.0
reactive_forms: ^16.1.1
reactive_forms_annotations: ^4.3.0
Here are the models:
The problem is that the
PermissionEntity
is being created as aFormControl<Map<String, Object?>>
and it won't read it as aFormGroup
. Unless I'm doing something wrong, I think there's something bad happening.I have used
FormArrays
asFormGroup
s and indeed it read it asFormControl<Map<String, Object?>>
but it works if I just cast it asFormGroup
maybe a cast is missing when getting the value.