form_bloc
form_bloc copied to clipboard
'(String) => Future<String>' is not a subtype of type '(dynamic) => Future<String>' is thrown
Hi,
I have a select field bloc instantiated like below:
final startTime = SelectFieldBloc( items: [], validators: [FieldBlocValidators.required], asyncValidatorDebounceTime: Duration(milliseconds: 300));
In the contructor and its implementation:
`AsyncBloc() { startTime.addAsyncValidators([_checkTimeSlotAvailability]); }
Future<String> _checkTimeSlotAvailability(String startTime) async { if (startTime.isEmpty) return null; final isAvailable = await appointmentService.isTimeSlotAvailable( _clientId, patientId, appointmentDate.value, startTime, endTime.value); return isAvailable ? "" : "Time slot is not available"; }`
Actually, there are a lot of text field blocs but adding the code "startTime.addAsyncValidators()" causes an exception message below: (String) => Future<String>' is not a subtype of type '(dynamic) => Future<String>
Hi, set the generic types
https://pub.dev/documentation/form_bloc/latest/form_bloc/SelectFieldBloc/SelectFieldBloc.html
SelectFieldBloc<String, dynamic>()
Hi, Thanks for the help! Yeah, it solves to my problem that the screen is now shown/displayed. However, I got this runtime exception and the field validations are not working anymore.
════════ Exception caught by scheduler library ═════════════════════════════════ setState() called after dispose(): _DropdownFieldBlocBuilderMobileState<Item>#9e487(lifecycle state: defunct, not mounted) ════════════════════════════════════════════════════════════════════════════════