buildForm method
Implementation
FormGroup buildForm(ComplaintsRegistrationState state) {
final complaintDetails = state.mapOrNull(
view: (value) => value.complaintsDetailsModel,
);
final shouldDisableForm = complaintDetails != null;
return fb.group(<String, Object>{
_dateOfComplaint: FormControl<DateTime>(
value: complaintDetails?.dateOfComplaint ?? DateTime.now(),
disabled: shouldDisableForm,
validators: [],
),
_administrativeArea: FormControl<String>(
value: localizations.translate((complaintDetails?.administrativeArea ??
ComplaintsSingleton().boundary.name)
.toString()),
disabled: shouldDisableForm,
validators: [Validators.required],
),
_complaintRaisedFor: FormControl<String>(
value: complaintDetails?.complaintRaisedFor,
disabled: shouldDisableForm,
validators: [Validators.required],
),
_complainantName: FormControl<String>(
value: complaintDetails?.complainantName,
disabled: shouldDisableForm,
validators: [Validators.required, Validators.maxLength(64)],
),
_complainantContactNumber: FormControl<String>(
value: complaintDetails?.complainantContactNumber,
disabled: shouldDisableForm,
validators: [
Validators.required,
Validators.delegate(
(validator) => CustomValidator.validMobileNumber(validator)),
Validators.minLength(10),
Validators.maxLength(10)
],
),
_supervisorName: FormControl<String>(
value: complaintDetails?.supervisorName,
disabled: shouldDisableForm,
validators: [Validators.maxLength(64)],
),
_supervisorContactNumber: FormControl<String>(
value: complaintDetails?.supervisorContactNumber,
disabled: shouldDisableForm,
validators: [
Validators.delegate(
(validator) => CustomValidator.validMobileNumber(validator)),
Validators.maxLength(10),
Validators.minLength(10),
],
),
_complaintDescription: FormControl<String>(
value: complaintDetails?.complaintDescription,
disabled: shouldDisableForm,
validators: [Validators.required, Validators.maxLength(1000)],
),
_complaintDetailsForm: FormControl<String>(
disabled: shouldDisableForm,
),
});
}