buildForm method
Implementation
FormGroup buildForm(BeneficiaryRegistrationState state) {
final individual = state.mapOrNull<IndividualModel>(
editIndividual: (value) {
if (value.projectBeneficiaryModel?.tag != null) {
context.read<DigitScannerBloc>().add(DigitScannerScanEvent(
barCode: [], qrCode: [value.projectBeneficiaryModel!.tag!]));
}
return value.individualModel;
},
create: (value) {
return value.individualModel;
},
summary: (value) {
return value.individualModel;
},
);
final searchQuery = state.mapOrNull<String>(
create: (value) {
return value.searchQuery;
},
);
return fb.group(<String, Object>{
_individualNameKey: FormControl<String>(
validators: [
Validators.required,
CustomValidator.requiredMin,
Validators.maxLength(200),
],
value: individual?.name?.givenName ?? searchQuery?.trim(),
),
_idTypeKey: FormControl<String>(
value: individual?.identifiers?.firstOrNull?.identifierType,
),
_idNumberKey: FormControl<String>(
validators: [Validators.required],
value: individual?.identifiers?.firstOrNull?.identifierId,
),
_dobKey: FormControl<DateTime>(
value: individual?.dateOfBirth != null
? DateFormat(Constants().dateFormat).parse(
individual!.dateOfBirth!,
)
: null,
),
_genderKey: FormControl<String>(value: getGenderOptions(individual)),
_mobileNumberKey:
FormControl<String>(value: individual?.mobileNumber, validators: [
CustomValidator.validMobileNumber,
CustomValidator.minPhoneNumValidation,
Validators.maxLength(10)
]),
});
}