form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

'(String) => Future<String>' is not a subtype of type '(dynamic) => Future<String>' is thrown

Open egenita opened this issue 3 years ago • 2 comments

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>

egenita avatar Jul 18 '20 06:07 egenita

Hi, set the generic types

https://pub.dev/documentation/form_bloc/latest/form_bloc/SelectFieldBloc/SelectFieldBloc.html

SelectFieldBloc<String, dynamic>()

GiancarloCode avatar Jul 18 '20 15:07 GiancarloCode

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) ════════════════════════════════════════════════════════════════════════════════ image

egenita avatar Jul 19 '20 01:07 egenita